【问题标题】:Cannot run Azure CLI task on yaml build无法在 yaml 构建上运行 Azure CLI 任务
【发布时间】:2020-06-29 16:37:08
【问题描述】:

我开始对 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 任务,也会发生同样的事情。

我在这里错过了什么?

【问题讨论】:

    标签: build azure-devops yaml azure-cli


    【解决方案1】:

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

    更多详情

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

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

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

    【讨论】:

    • 太棒了!感谢您在这里分享您的解决方案,您可以接受它作为答案!
    【解决方案2】:

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

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

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

    pool: 
      name: MyPrivateAgent
    

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

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

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

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

    pool:
      vmImage: 'ubuntu-latest'
    

    希望这会有所帮助。

    【讨论】:

    • 谢谢@leo-liu-msft - 问题实际上是由于缺乏权限引起的,请参阅下面的答案。我看不到错误消息,因为Multi-stage pipelines 功能被禁用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 2015-10-18
    • 2017-10-06
    • 2023-03-15
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多