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

How to add Pre Deployment and Post deployment approvals in multistage YAML pipeline?

我有一个包含两个阶段的多阶段 YAML 管道 1) 构建和 2) 部署。下面提到了部署阶段,我想在部署任务之前的那个阶段添加预部署批准。如何在多阶段 YAML 管道中添加预部署和 Post 部署批准?

stages:
- stage: 'Build'

# RESTORE
   # Some task implementation
# BUILD
   # Some task implementation
# PUBLISH
   # Some task implementation

# DEPLOY STAGE
- stage: 'Dev'
  displayName: 'Deploy to the dev environment'
  dependsOn: Build
  jobs:
  - deployment: Deploy
    pool:
      vmImage: 'ubuntu-16.04'
    environment: dev
    variables:
    - group: Release
    strategy:

# HOW TO ADD PRE DEPLOYMENT AND POST DEPLOYMENT APPROVALS?

      runOnce:
        deploy:
          steps:
          - download: current
            artifact: drop
          - task: AzureWebApp@1
            displayName: 'Azure App Service Deploy: website'
            inputs:
              azureSubscription: 'Resource Manager - Tailspin - Space Game'
              appName: '$(WebAppNameDev)'
              package: '$(Pipeline.Workspace)/drop/$(buildConfiguration)/*.zip'

对于这个问题,目前,手动批准和评估工件是唯一可用的检查,它们只能在环境、服务连接和代理池上配置。

要定义对环境的批准:

  1. 在你的Azure DevOps项目中,转到需要保护的环境。 (了解有关 creating an environment 的更多信息。)

  2. 导航至环境的批准和检查

  3. Select 创建,提供批准人和可选消息,然后 select 再次创建以完成添加手动批准检查。

然后在您的 yaml 文件中使用 environment: 'xxx' 参数。例如:

- stage: deploy
  jobs:
  - deployment: DeployWeb
    displayName: deploy Web App
    pool:
      vmImage: 'Ubuntu-16.04'
    # creates an environment if it doesn't exist
    environment: 'multiStage'

在这种情况下,GUI 和 yaml 是相互依赖的,它不是直接的 yaml。

详情请参考本官方document.