Azure DevOps (AZ-400)
Quick reference
Quick reference
Azure Pipelines YAML skeleton
yaml
trigger:
batch: true
branches: { include: [ main, release/* ] }
paths: { exclude: [ docs/* ] }
pr: none # Azure Repos: use branch policy build validation
schedules:
- cron: '0 2 * * 1-5' # UTC
displayName: Nightly
branches: { include: [ main ] }
always: false # only if code changed
resources:
repositories:
- repository: templates
type: git
name: Platform/pipeline-templates
ref: refs/tags/v3
pipelines:
- pipeline: ci
source: Shop-CI
trigger: { branches: { include: [ main ] } }
parameters:
- name: region
type: string
default: westeurope
values: [ westeurope, northeurope ]
variables:
- group: shop-prod-kv # Key Vault-linked variable group
- template: vars/common.yml
- name: buildConfiguration
value: Release
stages:
- stage: Build
jobs:
- job: Build
pool: { vmImage: ubuntu-latest }
steps:
- checkout: self
fetchDepth: 1
- task: Cache@2
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json'
path: $(NUGET_PACKAGES)
- script: dotnet test --collect:"XPlat Code Coverage"
- task: PublishCodeCoverageResults@2
inputs: { summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml' }
- publish: $(Build.ArtifactStagingDirectory)
artifact: drop
- stage: Prod
dependsOn: Build
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- deployment: Deploy
environment: prod # approvals & checks live on the environment
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
inputs:
azureSubscription: prod-arm # WIF service connection
appName: shop-prod
deployToSlotOrASE: true
slotName: staging
package: $(Pipeline.Workspace)/drop/**/*.zipExpression syntax
| Syntax | Evaluated | Use for |
|---|---|---|
| ${{ variables.x }} / ${{ parameters.p }} | Compile time (template expansion) | conditional insertion, loops, template params |
| $[ variables.x ] | Runtime, before the job starts | conditions, dependency outputs, counters |
| $(x) | Macro, just before a task runs | task inputs and scripts |
| dependencies.Job.outputs['step.var'] | Runtime (same stage) | pass values between jobs |
| stageDependencies.Stage.Job.outputs['step.var'] | Runtime (next stage) | pass values between stages |
| counter(prefix, seed) | Runtime | auto-increment build numbers per prefix |
GitHub Actions workflow skeleton (OIDC to Azure)
yaml
name: deploy
on:
push: { branches: [ main ] }
workflow_dispatch:
permissions:
id-token: write # request the OIDC token
contents: read
concurrency: { group: prod, cancel-in-progress: false }
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test
- uses: actions/upload-artifact@v4
with: { name: web, path: dist, retention-days: 14 }
deploy:
needs: build
runs-on: ubuntu-latest
environment: production # protection rules: reviewers, wait timer, branches
steps:
- uses: actions/download-artifact@v4
with: { name: web }
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- run: az webapp deploy -g rg-shop -n shop-prod --src-path web.zipGit commands you must recognize
| Goal | Command |
|---|---|
| Undo a pushed commit safely | git revert <sha> (merge commit: git revert -m 1 <sha>) |
| Undo local commits, keep changes staged | git reset --soft HEAD~2 |
| Find lost commits | git reflog, then git branch rescue <sha> |
| Copy one commit to another branch | git cherry-pick <sha> |
| Annotated tag + push | git tag -a v2.1.0 -m "Release 2.1.0"; git push origin v2.1.0 |
| Purge a file from all history | git filter-repo --path secrets.json --invert-paths |
| Track big binaries | git lfs track "*.psd"; git add .gitattributes |
| Convert history to LFS | git lfs migrate import --include="*.zip" --everything |
| Large monorepo clone | scalar clone <url> (partial clone + sparse checkout + maintenance) |
| Partial / shallow clone | git clone --filter=blob:none <url>; git clone --depth 1 <url> |
| Changelog from history | git log v2.0.0..v2.1.0 --pretty=format:"- %s (%h)" --no-merges |
Azure CLI / Azure DevOps CLI essentials
bash
az extension add --name azure-devops
az devops configure --defaults organization=https://dev.azure.com/contoso project=Shop
az pipelines create --name Shop-CI --yml-path azure-pipelines.yml --repository Shop
az pipelines run --name Shop-CI --branch main
az repos policy approver-count create --branch main --repository-id <id> \
--minimum-approver-count 2 --creator-vote-counts false --blocking true --enabled true
az artifacts universal publish --feed tools --name cli --version 1.4.0 --path ./bin
az boards work-item create --title "Investigate alert" --type Bug
# IaC
az bicep lint --file main.bicep
az deployment group what-if -g rg-shop --template-file main.bicep -p env=prod
az stack group create -n shop-stack -g rg-shop --template-file main.bicep \
--action-on-unmanage deleteResources --deny-settings-mode denyDelete
az webapp deployment slot swap -g rg-shop -n shop-prod --slot staging --target-slot production
az appconfig feature enable --name appcs-shop --feature Beta --label prodKQL cheat sheet
kql
// Failed requests per 5 minutes, last 24h
requests
| where timestamp > ago(24h) and success == false
| summarize failures = count() by bin(timestamp, 5m), resultCode
| render timechart
// P95 latency by operation (workspace-based table)
AppRequests
| where TimeGenerated > ago(1h)
| summarize p95 = percentile(DurationMs, 95), calls = count() by OperationName
| top 10 by p95 desc
// End-to-end trace for one operation
union requests, dependencies, exceptions, traces
| where operation_Id == '4bf92f3577b34da6a3ce929d0e0e4736'
| project timestamp, itemType, name, duration, success
| order by timestamp asc
// VM CPU average (Azure Monitor Agent / VM insights)
InsightsMetrics
| where Namespace == 'Processor' and Name == 'UtilizationPercentage'
| summarize avg(Val) by Computer, bin(TimeGenerated, 15m)
// Machines that stopped sending heartbeats
Heartbeat
| summarize last = max(TimeGenerated) by Computer
| where last < ago(15m)
// Who deleted resources?
AzureActivity
| where OperationNameValue endswith 'DELETE' and ActivityStatusValue == 'Success'
| project TimeGenerated, Caller, ResourceGroup, _ResourceIdDecision cheat sheet
| If the question says... | Think... |
|---|---|
| no secrets / no rotation for Azure auth | Workload identity federation (OIDC) or managed identity |
| share one identity across many resources | User-assigned managed identity |
| only approved pipeline structure may deploy | extends template + 'Required template' check |
| human sign-off before prod | Environment approval check (Actions: required reviewers) |
| block deploys while alerts fire | Query Azure Monitor alerts check / gate |
| consume nuget.org through one governed feed | Azure Artifacts upstream sources |
| share only tested package versions | Feed views: promote to @Release |
| zero-downtime web app release, quick rollback | Deployment slots + swap (swap back to roll back) |
| release to a % or group of users without redeploy | Feature flags (App Configuration) |
| expose to internal users, then wider audiences | Ring deployment |
| large binary files in Git | Git LFS |
| huge monorepo is slow | Scalar / partial clone / sparse checkout |
| secret was committed | Rotate secret FIRST, then git filter-repo/BFG, force-push |
| leaked secret should never reach the server | Secret scanning push protection |
| vulnerable open-source packages | Dependabot alerts / dependency scanning |
| SAST in the pipeline | CodeQL (GHAS / GHAS for Azure DevOps) |
| one view of security across GitHub + ADO + GitLab | Defender for Cloud DevOps security |
| audit + enforce OS config on Azure and Arc VMs | Azure Machine Configuration |
| developers self-serve compliant environments | Azure Deployment Environments |
| access to private network from hosted build | Managed DevOps Pools (VNet) / self-hosted agents |
| free access to work items and boards, no code | Stakeholder access level |
| trace a request across microservices | Application Insights: operation_Id, transaction view |
| VM CPU, memory, disk, network trends | VM insights (Azure Monitor Agent + DCR) |