如何在多阶段 YAML 管道中添加部署后批准?

时间:2021-05-26 12:13:38

标签: azure-devops azure-devops-pipelines

我有一个多级 YAML 管道,其中包含三个 QA 阶段 QA1,QA2,QA3。我必须向 QA3 添加部署后批准,即一旦 QA3 成功完成,它必须等待我的批准才能触发阶段 PROD 部署。如何实现这一目标?

2 个答案:

答案 0 :(得分:1)

根据您的要求,您可以尝试在 YAML 示例中使用 Environment

步骤如下:

步骤 1:在 Pipelines -> Environments 中创建环境并添加 Approvals and checks

enter image description here

第 2 步:在 YAML 管道中添加环境。

stages:
- stage: QA1
  jobs:
  - job: QA1
    steps:
      - script: echo 1

- stage: QA2
  jobs:
  - job: QA2
    steps:
      - script: echo 1

- stage: QA3
  jobs:
  - job: QA3
    steps:
      - script: echo 1

- stage: deploy
  jobs:
  - deployment: DeployWeb
    displayName: deploy Web App
    pool:
      vmImage: 'Ubuntu-latest'
    environment: 'Test'
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo Hello world

结果:

enter image description here

答案 1 :(得分:0)

没有部署后批准。你能做的是ManualValidation

- stage: CI
  jobs:
  - job: CI
    steps:
    - script: echo 'From CI'

- stage: UAT
  jobs:
  - job: UAT
    steps:
    - script: echo 'From UAT'
  
  - job: UATWaitForValidation
    displayName: Wait for external validation  
    pool: Server
    timeoutInMinutes: 4320 # job times out in 3 days
    steps:
    - task: ManualValidation@0
      timeoutInMinutes: 1440 # task times out in 1 day
      inputs:
        notifyUsers: $(users)
        instructions: 'Please validate the build configuration and resume'
        onTimeout: 'resume'

- stage: PROD
  jobs:
  - job: PROD
    steps:
    - script: echo 'From PROD'