AzureCLI@2 任务中的“错误:TF401444:请至少登录一次...”

问题描述 投票:0回答:1

我正在使用下面的 YAML 管道通过 Azure CLI 脚本创建 PR:-

  - task: AzureCLI@2
    inputs:
      azureSubscription: '${{ parameters.serviceConnection }}'
      scriptType: 'ps'
      scriptLocation: 'inlineScript'
      inlineScript: |
        # Set organization, project, and repository details
        $organization="https://dev.azure.com/MyOrg"
        $project="MyProject"
        $repository="MyRepo"
        $targetBranch = "refs/heads/dev"
        $sourceBranch = "refs/heads/feature/myfeature"

        # Set the pull request title and description
        $prTitle="Automated Pull Request"
        $prDescription="Auto-generated pull request for changes."

        # Create a pull request using az repos pr create
        az repos pr create --organization $organization --project $project --repository $repository --source-branch $sourceBranch --target-branch $targetBranch --title "$prTitle" --description "$prDescription"

我收到以下错误:-

# ["ERROR: TF401444: Please sign-in at least once..." in AzureCLI@2 task](https://stackoverflow.com/questions/77663812/error-tf401444-please-sign-in-at-least-once-in-azurecli2-task)

当在任务的

azureSubscription
属性中指定服务连接时,预计不需要显式登录。我已验证服务连接存在。

azure yaml devops pull-request azure-cli
1个回答
0
投票

交互式登录在 DevOps 管道的 Azure CLI 任务中不起作用。

您需要使用 PAT 令牌和

az devops login
在 Azure 存储库中创建 PR:-

我的 Azure DevOps yaml 管道:-

trigger:
- main

pool:
  vmImage: ubuntu-latest

variables:
  organization: https://dev.azure.com/sid24desai0738
  project: AzureDevops
  repository: streamlitapp
  targetBranch: main
  sourceBranch: myfeature
  prTitle: Automated Pull Request
  prDescription: Auto-generated pull request for changes
  AZURE_DEVOPS_EXT_PAT: xep3dv726tvoxilxxxxxxx3h4yjnpb6vnyhbjq

steps:
 - task: AzureCLI@2
   inputs:
     azureSubscription: 'xxx subscription (xxxxxx)'
     scriptType: 'bash'
     scriptLocation: 'inlineScript'
     inlineScript: |
       # Set Azure DevOps organization URL
             #export AZURE_DEVOPS_EXT_PAT=xxxxxtbjz6wyryhl3h4yjnpb6vnyhbjq
       
             # Azure CLI commands to interact with Azure DevOps
             echo $(AZURE_DEVOPS_EXT_PAT) | az devops login --organization https://dev.azure.com/sid24desai0738
               az repos pr create --org $(organization) --project $(project) --repository $(repository) --source-branch $(sourceBranch) --target-branch $(targetBranch) --title "$(prTitle)" --description "$prDescription"

输出:-

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.