无法在 yaml 构建上 运行 Azure CLI 任务

Cannot run Azure CLI task on yaml build

我开始对 yaml 构建失去理智。这是我尝试配置的第一个 yaml 构建,所以我可能犯了一些基本错误。

这是我的 yaml 构建定义:

name: ops-tools-delete-failed-containers-$(Date:yyyyMMdd)$(Rev:.rrrr)

trigger:
  branches:
    include:
      - master
      - features/120414-delete-failed-container-instances

schedules:
- cron: '20,50 * * * *'
  displayName: At minutes 20 and 50
  branches:
    include:
    - features/120414-delete-failed-container-instances
  always: 'true'

pool: 
  name: Standard-Windows

variables:
  - name: ResourceGroup
    value: myResourceGroup

stages:
  - stage: Delete
    displayName: Delete containers
    jobs:
      - job: Job1
        steps:
        - task: AzureCLI@2
          inputs:
            azureSubscription: 'CPA (Infrastructure) (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx)'
            scriptType: 'pscore'
            scriptLocation: 'scriptPath'
            scriptPath: 'General/Automation/ACI/Delete-FailedContainerInstances.ps1'
            arguments: '-ResourceGroup $(ResourceGroup)'

简而言之,我想 运行 使用 Azure CLI 任务的脚本。当我对一个新构建进行排队时,它永远保持这样:

我已经尝试 运行使用内联脚本执行相同的任务但没有成功。如果我尝试 运行 Powershell 任务而不是 Azure CLI 任务,也会发生同样的事情。

我在这里错过了什么?

Cannot run Azure CLI task on yaml build

您的 YAML 文件应该是正确的。我已经在我这边测试了你的 YAML,它工作正常。

我唯一修改的地方是用我的私人代理更改代理池:

pool: 
  name: MyPrivateAgent

另外,根据你图片中的状态:

所以,您为构建定义指定的代理队列下的私人代理似乎不是 运行:

创建代理 运行,然后构建将开始。

作为测试,您可以使用托管代理而不是您的私人代理,例如:

pool:
  vmImage: 'ubuntu-latest'

希望对您有所帮助。

TL;DR 问题是由(缺少)权限引起的。

更多详情

启用以下功能后,我可以看到有关该问题的更多详细信息:

启用该功能后显示以下警告:

单击 View 显示 Azure CLI 任务中使用的 Azure 订阅。单击 Permit 后,一切正常。