【问题标题】:Azure pipelines approval is required before the condition is evaluated在评估条件之前需要 Azure 管道批准
【发布时间】:2020-12-18 14:53:31
【问题描述】:

我有一个 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)

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

  - 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-devops yaml azure-pipelines azure-pipelines-release-pipeline azure-pipelines-yaml


【解决方案1】:

这里的问题是我想为发布设置批准 并且管道要求我在评估之前批准它 健康)状况。我希望仅在以下情况下获得批准请求 释放条件为真

对于这个问题,这里同意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是否为True,如果ReleaseConditionFalse,则stage为skipped,不检查审批。

- stage: 'S_ReleaseChannelUpdate'
    dependsOn:
      - S_BuildChannelUpdate

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多