Azure DevOps Pipelines
When to Use
- Building CI/CD pipelines in Azure DevOps for any language or platform
- Configuring YAML pipelines with stages, jobs, and deployment strategies
- Setting up deployment environments with approval gates and checks
- Choosing between Microsoft-hosted and self-hosted agents
- Implementing secure service connections with Workload Identity Federation
- Preparing for Azure DevOps Engineer Expert (AZ-400) exam
Core Jobs
1. Pipeline Structure (YAML)
trigger:
branches:
include: [main]
stages:
- stage: Build
jobs:
- job: BuildApp
pool:
vmImage: ubuntu-latest
steps:
- script: npm run build
- publish: dist
artifact: drop
- stage: Deploy
dependsOn: Build
jobs:
- deployment: DeployProd
environment: production
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop
- trigger: branches or paths that kick off CI
- stages: logical phases (Build, Test, Deploy); run sequentially by default
- jobs: run on agents; can run in parallel within a stage
- steps: individual tasks or scripts within a job
2. Agent Pools
| Agent Type |
Pros |
Cons |
Use When |
| Microsoft-hosted |
Zero maintenance; fresh VM per run; multiple OS |
No private network access; ephemeral (no caching) |
Public endpoints, standard build/test |
| Self-hosted |
VNet access; persistent tools cache; custom software |
You manage VMs/containers |
Private endpoints, AKS, SQL MI, on-prem resources |
- Microsoft-hosted images:
ubuntu-latest, windows-latest, macos-latest
- Self-hosted: install agent on VM, container, or use VMSS agent pool (auto-scale)
- Scale Set (VMSS) agent pool: auto-scale self-hosted agents based on queue depth
3. Environments and Approvals
- Environment = deployment target with history, approvals, and checks
- Define environment in YAML:
environment: production in deployment job
- Approval checks: require manual approval before deployment starts
- Branch control check: only allow deploy from
main or release/* branches
- Business hours check: restrict deployments to specific time windows
- Environment deployment history: full audit trail of what deployed when and by whom
4. Deployment Strategies
strategy:
# Option 1: runOnce (default)
runOnce:
deploy:
steps: [...]
# Option 2: rolling
rolling:
maxParallel: 25% # Update 25% of targets at a time
deploy:
steps: [...]
# Option 3: canary
canary:
increments: [10, 50] # 10% → 50% → 100%
deploy:
steps: [...]
postRouteTraffic:
steps: [...] # Validate before next increment
runOnce = deploy everything at once; simple, no rollback built-in
rolling = update subset of targets; reduces blast radius
canary = gradual traffic shift with validation gates; best for high-traffic services
5. Service Connections
- Service connection = reusable authentication to external systems (Azure, Docker, GitHub, npm)
- Azure service connection types:
- Workload Identity Federation (OIDC) — recommended; no secret rotation; uses federated credential
- Managed Identity — pipeline agent's Managed Identity authenticates to Azure
- Service Principal (secret) — legacy; requires secret rotation; avoid for new connections
- Create: Project Settings → Service Connections → New
- Workload Identity Federation setup: ADO creates app registration + federated credential automatically
6. Artifacts and Package Feeds
- Pipeline Artifacts:
publish/download steps; pass build outputs between stages
- Azure Artifacts: package feed for npm, NuGet, pip, Maven, Universal Packages
- Feed scoping: organization-level or project-level
- Upstream sources: proxy public registries (npmjs.com, PyPI) with caching
- Artifact retention: configure retention policies to clean up old artifacts
7. Branch Policies (Azure Repos)
- Require a minimum number of reviewers before merge
- Require linked work item for traceability
- Build validation: CI pipeline must pass before PR can complete
- Status checks: require external checks (Sonar, security scan) to pass
- Apply to
main and release/* branches; block direct push
Key Concepts
- YAML pipeline — defined as code in repo; version-controlled; preferred over Classic UI pipelines
- Environment — deployment target with approval gates, history, and compliance checks
- Workload Identity Federation — OIDC-based service connection; no secret rotation required
- Template — reusable pipeline YAML; reference across projects with
extends or template
- Variable groups — shared variables linked to pipeline; supports Key Vault-backed secrets
- Artifact — build output passed between stages; stored in Azure DevOps or external feed
Checklist
Output Format
- 🔴 Critical — service principal with password secret in service connection (no rotation plan)
- 🔴 Critical — no approval gate on production environment deployment job
- 🟡 Warning — Classic UI pipeline used (cannot be version-controlled; migrate to YAML)
- 🟡 Warning — Microsoft-hosted agent used for pipeline requiring access to private endpoints
- 🟢 Suggestion — use VMSS agent pool for self-hosted agents to auto-scale based on pipeline queue
Exam Tips
- YAML pipeline = code in repo — version-controlled; stored alongside application code; preferred over Classic pipeline which is UI-only
- Environment + approval gate = require manual approval before deployment to prod — configured in environment settings; recorded in deployment history
- Self-hosted agents = needed for private network access — AKS private cluster, SQL Managed Instance, on-premises resources all require self-hosted
- Workload Identity Federation = no secret rotation — ADO creates federated credential automatically; OIDC token exchange at runtime
- Template references = reuse pipeline code —
template: templates/build.yml@repo enables DRY pipelines across projects
- Branch policies: require PR + CI pass before merge — protect main/release branches from direct push and unvalidated changes
1---2name: azure-devops-pipelines3description: Use when building Azure Pipelines CI/CD workflows, configuring YAML pipelines, setting up deployment environments with approvals, choosing agent types, or studying for Azure DevOps Engineer Expert (AZ-400).4---56# Azure DevOps Pipelines78## When to Use9- Building CI/CD pipelines in Azure DevOps for any language or platform10- Configuring YAML pipelines with stages, jobs, and deployment strategies11- Setting up deployment environments with approval gates and checks12- Choosing between Microsoft-hosted and self-hosted agents13- Implementing secure service connections with Workload Identity Federation14- Preparing for Azure DevOps Engineer Expert (AZ-400) exam1516## Core Jobs1718### 1. Pipeline Structure (YAML)19```yaml20trigger:21 branches:22 include: [main]2324stages:25 - stage: Build26 jobs:27 - job: BuildApp28 pool:29 vmImage: ubuntu-latest30 steps:31 - script: npm run build32 - publish: dist33 artifact: drop3435 - stage: Deploy36 dependsOn: Build37 jobs:38 - deployment: DeployProd39 environment: production40 strategy:41 runOnce:42 deploy:43 steps:44 - download: current45 artifact: drop46```47- **trigger**: branches or paths that kick off CI48- **stages**: logical phases (Build, Test, Deploy); run sequentially by default49- **jobs**: run on agents; can run in parallel within a stage50- **steps**: individual tasks or scripts within a job5152### 2. Agent Pools53| Agent Type | Pros | Cons | Use When |54|------------|------|------|---------|55| **Microsoft-hosted** | Zero maintenance; fresh VM per run; multiple OS | No private network access; ephemeral (no caching) | Public endpoints, standard build/test |56| **Self-hosted** | VNet access; persistent tools cache; custom software | You manage VMs/containers | Private endpoints, AKS, SQL MI, on-prem resources |5758- Microsoft-hosted images: `ubuntu-latest`, `windows-latest`, `macos-latest`59- Self-hosted: install agent on VM, container, or use VMSS agent pool (auto-scale)60- **Scale Set (VMSS) agent pool**: auto-scale self-hosted agents based on queue depth6162### 3. Environments and Approvals63- **Environment** = deployment target with history, approvals, and checks64- Define environment in YAML: `environment: production` in deployment job65- **Approval checks**: require manual approval before deployment starts66- **Branch control check**: only allow deploy from `main` or `release/*` branches67- **Business hours check**: restrict deployments to specific time windows68- Environment deployment history: full audit trail of what deployed when and by whom6970### 4. Deployment Strategies71```yaml72strategy:73 # Option 1: runOnce (default)74 runOnce:75 deploy:76 steps: [...]7778 # Option 2: rolling79 rolling:80 maxParallel: 25% # Update 25% of targets at a time81 deploy:82 steps: [...]8384 # Option 3: canary85 canary:86 increments: [10, 50] # 10% → 50% → 100%87 deploy:88 steps: [...]89 postRouteTraffic:90 steps: [...] # Validate before next increment91```92- `runOnce` = deploy everything at once; simple, no rollback built-in93- `rolling` = update subset of targets; reduces blast radius94- `canary` = gradual traffic shift with validation gates; best for high-traffic services9596### 5. Service Connections97- **Service connection** = reusable authentication to external systems (Azure, Docker, GitHub, npm)98- Azure service connection types:99 - **Workload Identity Federation (OIDC)** — recommended; no secret rotation; uses federated credential100 - **Managed Identity** — pipeline agent's Managed Identity authenticates to Azure101 - **Service Principal (secret)** — legacy; requires secret rotation; avoid for new connections102- Create: Project Settings → Service Connections → New103- Workload Identity Federation setup: ADO creates app registration + federated credential automatically104105### 6. Artifacts and Package Feeds106- **Pipeline Artifacts**: `publish`/`download` steps; pass build outputs between stages107- **Azure Artifacts**: package feed for npm, NuGet, pip, Maven, Universal Packages108 - Feed scoping: organization-level or project-level109 - Upstream sources: proxy public registries (npmjs.com, PyPI) with caching110- **Artifact retention**: configure retention policies to clean up old artifacts111112### 7. Branch Policies (Azure Repos)113- **Require a minimum number of reviewers** before merge114- **Require linked work item** for traceability115- **Build validation**: CI pipeline must pass before PR can complete116- **Status checks**: require external checks (Sonar, security scan) to pass117- Apply to `main` and `release/*` branches; block direct push118119## Key Concepts120- **YAML pipeline** — defined as code in repo; version-controlled; preferred over Classic UI pipelines121- **Environment** — deployment target with approval gates, history, and compliance checks122- **Workload Identity Federation** — OIDC-based service connection; no secret rotation required123- **Template** — reusable pipeline YAML; reference across projects with `extends` or `template`124- **Variable groups** — shared variables linked to pipeline; supports Key Vault-backed secrets125- **Artifact** — build output passed between stages; stored in Azure DevOps or external feed126127## Checklist128- [ ] YAML pipeline used (not Classic UI pipeline) for version-controlled CI/CD?129- [ ] Workload Identity Federation configured for Azure service connections (no secrets)?130- [ ] Environments defined with approval checks for production deployments?131- [ ] Branch policies enforcing PR review + CI pass before merge to main?132- [ ] Self-hosted agents used when pipeline needs access to private network resources?133- [ ] Template references used to avoid duplicating pipeline code across projects?134- [ ] Key Vault-backed variable group used for pipeline secrets (not hardcoded values)?135136## Output Format137- 🔴 **Critical** — service principal with password secret in service connection (no rotation plan)138- 🔴 **Critical** — no approval gate on production environment deployment job139- 🟡 **Warning** — Classic UI pipeline used (cannot be version-controlled; migrate to YAML)140- 🟡 **Warning** — Microsoft-hosted agent used for pipeline requiring access to private endpoints141- 🟢 **Suggestion** — use VMSS agent pool for self-hosted agents to auto-scale based on pipeline queue142143## Exam Tips144- **YAML pipeline = code in repo** — version-controlled; stored alongside application code; preferred over Classic pipeline which is UI-only145- **Environment + approval gate = require manual approval before deployment to prod** — configured in environment settings; recorded in deployment history146- **Self-hosted agents = needed for private network access** — AKS private cluster, SQL Managed Instance, on-premises resources all require self-hosted147- **Workload Identity Federation = no secret rotation** — ADO creates federated credential automatically; OIDC token exchange at runtime148- **Template references = reuse pipeline code** — `template: templates/build.yml@repo` enables DRY pipelines across projects149- **Branch policies: require PR + CI pass before merge** — protect main/release branches from direct push and unvalidated changes