Azure DevOps Multi-Stage Deployments with Approvals

Multi-stage YAML pipelines can include approvals and checks. Here’s how to build a proper deployment pipeline with staging and production environments.

Environment Setup

First, create environments in Azure DevOps: Pipelines → Environments. Add approval checks to Production.

Multi-Stage Pipeline

stages:
  - stage: Build
    jobs:
      - job: Build
        steps:
          - task: DotNetCoreCLI@2
            inputs:
              command: 'publish'
              publishWebProjects: true
              
  - stage: DeployStaging
    dependsOn: Build
    jobs:
      - deployment: Staging
        environment: Staging
        strategy:
          runOnce:
            deploy:
              steps:
                - task: AzureWebApp@1
                  inputs:
                    appName: 'myapp-staging'
                    
  - stage: DeployProduction
    dependsOn: DeployStaging
    condition: succeeded()
    jobs:
      - deployment: Production
        environment: Production  # Has approval gate
        strategy:
          runOnce:
            deploy:
              steps:
                - task: AzureWebApp@1
                  inputs:
                    appName: 'myapp-prod'

Approval Flow

When the pipeline reaches Production stage, it pauses for approval. Approvers get email notification and can approve/reject in Azure DevOps or Teams.


Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.