跳过阶段,在Azure DevOps Pipelines(YAML)中进行手动批准 [英] Skip stage with manual approval in Azure DevOps Pipelines (YAML)

查看:50
本文介绍了跳过阶段,在Azure DevOps Pipelines(YAML)中进行手动批准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Terraform部署,我们使用一个Azure DevOps管道,该管道具有3个阶段:

  1. 计划
  2. 申请(手动批准)
  3. 测试

在申请阶段,我们使用具有手动批准(检查)环境的部署作业.我们希望拥有的是跳过"如果计划阶段未显示任何更改,则为应用和测试阶段.因此,我们尝试在应用阶段使用以下yaml配置:

 -阶段:ApplySharedDependOn:PlanShared职位:-工作:CheckSharedChanges脚步:-任务:DownloadPipelineArtifact @ 2输入:artifactName:TerraformBuild下载路径:$(System.DefaultWorkingDirectory)-重击:|#使用一个文件来指示TF计划的更改,因为#您无法在Azure DevOps的各个阶段之间传递变量如果[-f".shared-changes"];然后回声"## vso [task.setvariable variable = shared_changes]是"科幻名称:支票-部署:ApplySharedDependOn:CheckSharedChanges#如果有手册,这个条件似乎可以忽略#舞台上的批准条件:eq(dependencies.CheckSharedChanges.outputs ['Check.shared_env'],'是')displayName:应用-共享"#我们为此环境配置了手动批准(检查),#,以便管道停止并要求操作员批准部署环境:红外共享" 

根据此

For our Terraform Deployment, we use an Azure DevOps pipeline that has 3 stages:

  1. plan
  2. apply (manual approval)
  3. test

For the apply stage we use a deployment job with an environment that has a manual approval (check). What we would like to have is "skipping" the apply and test stage, if the plan stage has shows no changes. Therefore we try to use the following yaml configuration for the apply stage:

  - 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'

According to this issue on the MS Developer Community, a condition on a stage with an approval is not checked before the approval, so the approach does not work.

My question is: do you know any other way to implement this?

Edit

There now exists a hacky workaround for this issue, see this SO post

解决方案

A stage can consist of many jobs, and each job can consume several resources. Before the execution of a stage can begin, all checks on all the resources used in that stage must be satisfied. Azure Pipelines pauses the execution of a pipeline prior to each stage, and waits for all pending checks to be completed. That's why the condition doesn't work in your scenario. Check more information here:

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass

There is already a similar idea on roadmap, you may track the following link:

https://developercommunity.visualstudio.com/idea/697467/manually-triggered-stages-in-yaml-multi-stage-pipe.html

Currently, you may consider starting a manual run and skip a few stages in your pipeline:

这篇关于跳过阶段,在Azure DevOps Pipelines(YAML)中进行手动批准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆