Roadmap › Azure DevOps & CI/CD › Module: Azure Pipelines
Lessons in this course (10)

4. Multi-stage CD with environments and approvals

Intermediate★ Must knowLesson 4 of 10
yaml
- stage: DeployDev
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: DeployApi
    environment: shop-dev                 # environment = deployment target + history + checks
    strategy:
      runOnce:
        deploy:
          steps:
          - download: current
            artifact: api
          - task: AzureWebApp@1
            inputs:
              azureSubscription: sc-shop-dev            # service connection (workload identity federation)
              appName: app-shop-dev
              package: $(Pipeline.Workspace)/api

- stage: DeployProd
  dependsOn: DeployDev
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
  jobs:
  - deployment: DeployApi
    environment: shop-prod                # approvals & checks configured on this environment in the UI
    strategy:
      runOnce:
        deploy:
          steps:
          - download: current
            artifact: api
          - task: AzureWebApp@1
            inputs:
              azureSubscription: sc-shop-prod
              appName: app-shop-prod
              package: $(Pipeline.Workspace)/api
              deployToSlotOrASE: true
              resourceGroupName: rg-shop-prod
              slotName: staging
          - task: AzureAppServiceManage@0
            inputs: { azureSubscription: sc-shop-prod, Action: Swap Slots, WebAppName: app-shop-prod, ResourceGroupName: rg-shop-prod, SourceSlot: staging }

Deployment job strategies: runOnce, rolling (VMs), canary (with increments). Approvals and checks on environments: manual approvals, branch control, business hours, Azure Monitor alerts query, invoke REST/Azure Function, exclusive lock, required template.