首页 > 解决方案 > 在评估条件之前需要 Azure 管道批准

问题描述

我有一个包含多个项目的解决方案的 CI/CD 管道。我检查更改并仅构建已更改的项目,而不是构建所有项目。我在每个项目的构建阶段使用条件来完成此操作。这是相关部分:

  - stage: S_BuildChannelUpdate
    dependsOn: 'PreSteps'
    jobs:
    - job: 'BuildChannelUpdate'
      variables:
        BuildCondition: $[ stageDependencies.PreSteps.Check_changes.outputs['pwsh_script.BuildChannelUpdate'] ]
      condition: eq(variables['BuildCondition'], True)

这正如我所料,只有在满足条件时才会执行构建步骤。到现在为止还挺好。对于部署部分,我只想在有新的部署时才这样做。即项目已更改,构建成功。同样,这里是相关部分:

  - stage: 'S_ReleaseChannelUpdate'
    dependsOn:
      - PreSteps
      - S_BuildChannelUpdate
    jobs:
    - deployment: 'ReleaseChannelUpdate'
      variables:
        ReleaseCondition: $[ stageDependencies.PreSteps.Check_changes.outputs['pwsh_script.BuildChannelUpdate'] ]
      condition: eq(variables['ReleaseCondition'], True)
      environment: 'dev'
      strategy:
        runOnce:
          deploy:
            steps:

这里的问题是我想为发布设置批准,并且管道要求我在评估条件之前批准它。只有当ReleaseCondition为 True时,我才想获得批准请求。我还期待由于S_BuildChannelUpdate阶段被跳过(条件不满足),S_ReleaseChannelUpdate阶段将认为它的依赖关系不满足。

有什么建议么?

标签: azure-devopsyamlazure-pipelinesazure-pipelines-release-pipelineazure-pipelines-yaml

解决方案


这里的问题是我想为发布设置批准,并且管道要求我在评估条件之前批准它。仅当 ReleaseCondition 为 True 时,我才想获得批准请求

对于这个问题,这里同意PaulVrugt。批准在阶段级别执行。Azure Pipelines 在每个阶段之前暂停管道的执行,并等待所有挂起的检查完成。如果条件是在作业级别设置的,在批准之前不会执行条件,所以作为解决方案,我们需要在阶段级别设置条件。

例如:

- stage: 'S_ReleaseChannelUpdate'
    dependsOn:
      - PreSteps
      - S_BuildChannelUpdate
    condition: eq(variables['ReleaseCondition'], True)
    jobs:
    - deployment: 'ReleaseChannelUpdate'
      environment: 'dev'
      strategy:
        runOnce:
          deploy:
            steps:

有了这个定义,在执行审批之前,pipeline会先判断是否ReleaseCondition为is True,如果ReleaseConditionFalse,则stage为skipped和不检查审批。

- stage: 'S_ReleaseChannelUpdate'
    dependsOn:
      - S_BuildChannelUpdate

为此,如果S_BuildChannelUpdate跳过了阶段(不满足条件),S_ReleaseChannelUpdate也将跳过该阶段


推荐阅读