【发布时间】:2020-08-13 15:46:34
【问题描述】:
对于我们的 Terraform 部署,我们使用具有 3 个阶段的 Azure DevOps 管道:
- 计划
- 申请(人工审批)
- 测试
对于应用阶段,我们使用具有手动批准(检查)环境的部署作业。如果计划阶段没有显示任何变化,我们想要的是“跳过”应用和测试阶段。因此,我们尝试在应用阶段使用以下 yaml 配置:
- stage: ApplyShared
dependsOn: PlanShared
jobs:
- job: CheckSharedChanges
steps:
- task: DownloadPipelineArtifact@2
inputs:
artifactName: TerraformBuild
downloadPath: $(System.DefaultWorkingDirectory)
- bash: |
# using a file for indicating changes in TF plan, since
# you cannot pass variables between stages in Azure DevOps
if [ -f ".shared-changes" ]; then
echo '##vso[task.setvariable variable=shared_changes]yes'
fi
name: Check
- deployment: ApplyShared
dependsOn: CheckSharedChanges
# this condition seems to be ignored, if there is a manual
# approval on the stage
condition: eq(dependencies.CheckSharedChanges.outputs['Check.shared_env'], 'yes')
displayName: 'Apply - shared'
# we configured a manual approval (check) for this environment,
# so the pipeline stops and asks for an operator to approve the deployment
environment: 'infra-shared'
根据这个issue on the MS Developer Community,在审批前不检查已审批阶段的条件,所以该方法行不通。
我的问题是:你知道有什么其他方法可以实现吗?
编辑
现在有一个解决此问题的 hacky 解决方法,请参阅 this SO post
【问题讨论】:
标签: azure-devops yaml terraform azure-pipelines