The recommended approach is to use Azure DevOps Environments with Approvals and Checks rather than implementing approval logic entirely within the YAML pipeline.
Azure DevOps provides environment-level approval controls that are managed outside the YAML file. This is particularly useful because pipeline authors cannot simply remove these checks by modifying their YAML definition.
Step 1: Create Azure DevOps Environments
Navigate to:
Pipelines → Environments → New Environment
Create the following environments:
Development
QA
UAT
Production
These environments provide deployment history, resource tracking, and deployment control.
Step 2: Configure approval checks
For UAT and Production:
Open the respective environment.
- Navigate to Approvals and checks.
Select Approvals.
Add the required approvers or groups.
Configure the approval timeout and other required settings.
Save the configuration.
For example:
UAT: QA Lead or Testing Team.
Production: Release Manager or Production Support Team.
Approvals are configured outside the YAML pipeline, which provides an additional security boundary.
Step 3: Implement a multi-stage YAML pipeline
Below is an example:
trigger:
- main
pool:
vmImage: ubuntu-latest
stages:
- stage: Build
displayName: Build Application
jobs:
- job: BuildJob
steps:
- script: echo "Building application..."
displayName: Build
- stage: Development
displayName: Deploy to Development
dependsOn: Build
jobs:
- deployment: DeployDev
environment: Development
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying to Development"
- stage: QA
displayName: Deploy to QA
dependsOn: Development
jobs:
- deployment: DeployQA
environment: QA
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying to QA"
- stage: UAT
displayName: Deploy to UAT
dependsOn: QA
jobs:
- deployment: DeployUAT
environment: UAT
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying to UAT"
- stage: Production
displayName: Deploy to Production
dependsOn: UAT
condition: succeeded()
jobs:
- deployment: DeployProduction
environment: Production
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying to Production"
Note: This is a simplified example demonstrating deployment sequencing. Replace the echo commands with actual deployment tasks for your application.
Step 4: Understand how the approval process works
When the pipeline reaches the UAT stage, Azure DevOps evaluates the approval checks configured on the UAT environment.
If approved, the UAT deployment proceeds.
If rejected, the stage does not proceed.
If the approval times out, the stage fails according to the configured timeout behavior.
The Production stage starts only after UAT completes successfully and the Production environment's approval checks are satisfied.
Step 5: Prevent approval bypass
For production environments, consider the following security measures:
Configure approvals and checks directly on the Production environment.
Restrict environment administrator permissions to trusted administrators.
Avoid granting unnecessary permissions to pipeline contributors.
Use dedicated security groups for approvers.
Restrict who can administer or modify approval checks.
Use branch control checks to ensure deployments originate from approved branches.
Remember that environment-level checks are managed outside the YAML definition, but users with sufficient administrative permissions can still modify them. Restrict those permissions appropriately.