ERROR: The requested resource requires user authentication: in AzureCLI task build pipeline

ERROR: The requested resource requires user authentication: in AzureCLI task build pipeline

我无法从 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