azure-devops - 在评估条件之前需要 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阶段将认为它的依赖关系不满足。
有什么建议么?
解决方案
这里的问题是我想为发布设置批准,并且管道要求我在评估条件之前批准它。仅当 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
,如果ReleaseCondition
是False
,则stage为skipped
和不检查审批。
- stage: 'S_ReleaseChannelUpdate'
dependsOn:
- S_BuildChannelUpdate
为此,如果S_BuildChannelUpdate
跳过了阶段(不满足条件),S_ReleaseChannelUpdate
也将跳过该阶段
推荐阅读
- xcode - 反应原生 xcode 错误 | ld: 找不到 -lAppAuth 的库
- android - 无法打开相机意图。queryIntentActivities 在 api 级别 30 返回一个空列表,但在级别 29 中找到结果。发生了什么变化?
- ruby - BFS - 树遍历
- javascript - 当其中一个用于生成随机数时,Javascript 中的双方括号符号如何工作?
- javascript - 正则表达式匹配纯文本文件中的多个返回和单个返回
- sql - 如何从不同的数据库中查询表?
- c++ - 使用 Promise 和 Future 提供从一个线程到另一个线程的连续定期通知
- python - Python:如何引用数据结构中的元素 [{
- azure - 使用资源所有者密码凭据流的 AD B2C 非交互式/无头身份验证
- c# - 如何从列表中获取重复的项目子字符串?C#