azure - 错误: The requested resource requires user authentication: in AzureCLI task build pipeline

标签 azure azure-devops azure-pipelines azure-cli azure-pipelines-yaml

我无法从 azureCLI 任务触发 azure 管道构建

任务:

- task: AzureCLI@2
  inputs:
    azureSubscription: 'Free Trial(My subscription)'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az --version
      echo "Running : az account show"
      az account show
      #export AZURE_DEVOPS_EXT_PAT='mypat'
      $env:AZURE_DEVOPS_EXT_PAT='mypat'
      az pipelines create --name newPipeline --org https://dev.azure.com/AbiNilOrg/ --project azure-devops-kubernetes-terraform --branch master

有错误的输出:

Running : az account show
{
  "environmentName": "AzureCloud",
  "homeTenantId": "***",
  "id": "73c1af29-384c-4574-bd88-92d7bb392cfc",
  "isDefault": true,
  "managedByTenants": [],
  "name": "Free Trial",
  "state": "Enabled",
  "tenantId": "***",
  "user": {
    "name": "***",
    "type": "servicePrincipal"
  }
}
WARNING: This command is in preview and under development. Reference and support 
levels: https://aka.ms/CLI_refstatus
ERROR: The requested resource requires user authentication: 
https://dev.azure.com/AbiNilOrg/azure-devops-kubernetes- 
terraform/_apis/serviceendpoint/endpoints
##[error]Script failed with exit code: 1

据我所知,azure 无法形成正确的 URI 来到达休息点

ERROR: The requested resource requires user authentication: 
https://dev.azure.com/AbiNilOrg/azure-devops-kubernetes- 
terraform/_apis/serviceendpoint/endpoints

URI 的后缀 serviceendpoint/endpoints 不正确。

ADO 伙计们,如果对此有任何想法请帮忙!

提前致谢! 尼洛特帕尔

最佳答案

当您设置env:AZURE_DEVOPS_EXT_PAT时,您仍然需要通过调用登录:

az devops login --organization https://dev.azure.com/contoso

因为:

If you have already signed in with az login interactively or using user name and password, then you don't have to provide a token as az devops commands now support sign in through az login. However, service principal log in via az login isn't supported, in which case a PAT token is required.

这里的任务是通过服务主体登录场景,您也可以在帐户显示中看到:

  "user": {
    "name": "***",
    "type": "servicePrincipal"
  }

有关更多详细信息,请查看文档 here

关于azure - 错误: The requested resource requires user authentication: in AzureCLI task build pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68334416/

相关文章:

json - 如何检查名称是否已经存在? Azure 资源管理器模板

azure - 如何将 SAML 外部身份提供商添加到 Azure Active Directory?

Azure 逻辑应用程序 : "The EXECUTE permission was denied on the object ' MyProcName', 数据库 'dbName' ,架构 'dbo' 。”

azure-devops - 适用于 Azure DevOps 的带有 azure-pipelines.yml 的 SpecFlow 示例

.net - 事件的 Web 套接字连接是否使用 Azure 中的 CPU 时间?

c# - 由于 WebRequestHandler,Web 应用程序在部署到 azure 后崩溃

azure - 在 Azure DevOps 管道中为 WebApp 创建部署槽

node.js - 以编程方式跨 Azure、VSTS 和 Graph 访问 Microsoft 身份

azure-devops - Azure DevOps 在构建主机之间传递动态分配的变量

testing - VSTS 中 .NET Core 项目的代码覆盖率和测试结果