Search code examples
azure-devopsyamlazure-deploymentmultistage-pipeline

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


I have a Multistage YAML pipeline containing two stages 1) Build and 2) Deploy. Deploy stage is mentioned below and I want to add pre deploy approvals in that stage before deploy task. How can I add pre deployment and Post deployment approvals in multistage YAML pipeline?

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'

Solution

  • For this issue ,currently, manual approval and evaluate artifact are the only available checks, and they can be configured on environments, service connections and agent pools only.

    To define an approval on an environment:

    1. In your Azure DevOps project, go to the environment that needs to be protected. (Learn more about creating an environment.)

      enter image description here

    2. Navigate to Approvals and Checks for the environment.

      enter image description here

    3. Select Create, provide the approvers and an optional message, and select Create again to to complete addition of the manual approval check.

    Then use the environment: 'xxx' parameter in your yaml file. For example:

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

    The GUI and the yaml are interdependent in this case, it's not straight yaml.

    For details ,please refer to this official document.