Hands-on labs
A free Azure DevOps organization, a GitHub account and an Azure subscription are enough for almost every lab. Tick steps off as you go; your ticks are remembered in this browser. Delete resource groups afterwards to avoid charges.
Processes and communications
Connect Azure Boards to GitHub and trace a work item end to end
LAB-D1-01
Connect an Azure DevOps project (Agile process) to a GitHub repository with the Azure Boards app, then drive a user story from New to Resolved purely through GitHub activity: create a branch from the work item, commit with AB# references, open and merge a PR with a 'Fixes' keyword, and enforce linking with a required status check. You will observe exactly which mentions link and which transition state.
You need
- Azure DevOps organization with a project using the Agile process (Project Administrator)
- GitHub organization or account where you can install apps and edit branch protection
- A GitHub repository with a default branch main
- Git CLI
Steps
Show solution code
git checkout feature/101-throttle
echo "rate_limit: 5" >> config/auth.yml
git add config/auth.yml
git commit -m "Add per-IP login throttling
Sliding window of 5 attempts per minute.
AB#101 AB#102"
git push -u origin feature/101-throttle
# PR description (not title):
# Fixes AB#101
# Related AB#102
# Transition several items at once - repeat the keyword:
# Fixes AB#101, Fixes AB#104
# .github/workflows/require-ab-link.yml
# name: require-ab-link
# on:
# pull_request:
# types: [opened, edited, synchronize, reopened]
# jobs:
# check:
# runs-on: ubuntu-latest
# steps:
# - env:
# BODY: ${{ github.event.pull_request.body }}
# run: |
# echo "$BODY" | grep -qE 'AB#[0-9]+' || { echo "No AB# link"; exit 1; }Check your work
- Story 101 shows the branch, commit, PR and merge commit in Development and its state is Resolved.
- Story 102 shows commit and PR links but its state is unchanged.
- Story 103 has no GitHub links.
- A PR without AB# cannot be merged because the required require-ab-link check fails.
- The README shows the board badge with column counts.
Go further
- Merge a PR with 'Fixes AB#105' into a non-default branch and confirm only a link is created.
- Use 'Closed AB#106' to transition directly to a named state.
- Repeat the integration with a GitHub Enterprise Server instance or a second repository.
Build a flow-metrics dashboard with WIQL, widgets and Analytics OData
LAB-D1-02
Create a team dashboard that shows the flow of work (lead time, cycle time, CFD, velocity, burndown) plus quality and delivery signals, back it with shared WIQL queries, and reproduce the cycle-time and pipeline success figures through Analytics OData for Power BI.
You need
- Azure DevOps project with at least two completed sprints of work items
- A YAML pipeline with a few runs
- Azure CLI with the azure-devops extension
- View analytics permission
- Power BI Desktop (optional)
Steps
Show solution code
-- Open critical bugs (flat list)
SELECT [System.Id], [System.Title], [System.AssignedTo], [System.State]
FROM WorkItems
WHERE [System.TeamProject] = @Project
AND [System.WorkItemType] = 'Bug'
AND [Microsoft.VSTS.Common.Severity] = '1 - Critical'
AND [System.State] NOT IN ('Closed', 'Removed')
-- Completed stories with lead/cycle time (OData)
https://analytics.dev.azure.com/{org}/{project}/_odata/v4.0-preview/WorkItems?
$filter=WorkItemType eq 'User Story' and StateCategory eq 'Completed'
and CompletedDate ge 2026-07-01Z
&$select=WorkItemId,Title,LeadTimeDays,CycleTimeDays
-- Pipeline success counts (OData)
https://analytics.dev.azure.com/{org}/{project}/_odata/v4.0-preview/PipelineRuns?
$apply=filter(Pipeline/PipelineName eq '{pipeline}' and CompletedDate ge 2026-09-01Z)
/aggregate($count as Total, SucceededCount with sum as Succeeded)Check your work
- The dashboard renders all widgets without configuration errors.
- Query Tile count matches the CLI query result count.
- Average CycleTimeDays from OData is close to the Cycle Time widget's average for the same period.
- You can explain a CFD band's vertical thickness (WIP) and horizontal span (cycle time).
Go further
- Create an Analytics view for the team and build a Power BI report from it.
- Add a custom 'Incident' work item type and chart its lead time as a time-to-recovery proxy.
- Add a DORA panel: deployment frequency from environment history via the REST API.
Docs as code: code wiki with Mermaid and automated release notes
LAB-D1-03
Publish a repository folder as a versioned code wiki containing Markdown and Mermaid process diagrams, then add a pipeline stage that generates release notes from Conventional Commit history and work item references between tags and publishes them to the project wiki; finally configure GitHub-style generated release notes with .github/release.yml for comparison.
You need
- Azure DevOps project with an Azure Repos Git repo and a provisioned project wiki
- Permission to publish wikis and to grant the build service Contribute on the wiki repo
- Optional: a GitHub repository and the gh CLI
Steps
Show solution code
trigger:
tags:
include: ['v*']
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
fetchDepth: 0
fetchTags: true
persistCredentials: true
- bash: |
chmod +x build/release-notes.sh && ./build/release-notes.sh
cat RELEASE_NOTES.md
displayName: Generate release notes from git history
- bash: |
git config --global user.email "build@fabrikam.com"
git config --global user.name "Build"
git clone "https://$(System.AccessToken)@dev.azure.com/$ORG/$PROJ/_git/$PROJ.wiki" wiki
mkdir -p wiki/Release-Notes
cp RELEASE_NOTES.md "wiki/Release-Notes/$(Build.SourceBranchName).md"
cd wiki && git add -A && git commit -m "Notes $(Build.SourceBranchName)" && git push
displayName: Publish to project wiki
env:
ORG: fabrikam
PROJ: Shop
- publish: RELEASE_NOTES.md
artifact: release-notesCheck your work
- The code wiki shows a version selector with main and release/1.0.
- Mermaid diagrams render; the TOC lists the page headings.
- The pipeline run artifact contains RELEASE_NOTES.md with feat/fix sections and AB# IDs.
- The project wiki has Release-Notes/v1.1.0.
- The GitHub release body is grouped by your release.yml categories.
Go further
- Replace the bash script with release-please or git-cliff and derive the next SemVer automatically.
- Generate a DocFX site or OpenAPI document in the same pipeline and publish it to Azure Static Web Apps.
- Add a markdown link checker step that fails the build on broken wiki links.
Webhooks, service hooks and Teams ChatOps
LAB-D1-04
Wire Azure DevOps and GitHub events to external consumers and to Microsoft Teams: an Azure DevOps service hook that posts bug updates to a webhook receiver and a Service Bus queue, a GitHub webhook with signature verification, and Teams channel subscriptions for Boards, Pipelines and GitHub, including deployment approval from the channel.
You need
- Azure DevOps project (Project Administrator) with a YAML pipeline using an environment with an approval check
- GitHub repository (admin)
- Microsoft Teams channel where you can add apps
- Azure subscription for a Service Bus namespace (optional)
- A public HTTPS endpoint for testing (e.g. a request-inspection site or an Azure Function)
Steps
Show solution code
# Azure Function (Python) - verify GitHub webhook signature
import hmac, hashlib, os, json
import azure.functions as func
SECRET = os.environ["GH_WEBHOOK_SECRET"].encode()
def main(req: func.HttpRequest) -> func.HttpResponse:
body = req.get_body()
sig = req.headers.get("X-Hub-Signature-256", "")
expected = "sha256=" + hmac.new(SECRET, body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, sig):
return func.HttpResponse("bad signature", status_code=401)
event = req.headers.get("X-GitHub-Event")
payload = json.loads(body)
# enqueue for async processing; respond fast (GitHub times out after 10 s)
return func.HttpResponse(f"ok {event} {payload.get('action')}", status_code=202)Check your work
- Service hook History shows successful deliveries for both consumers.
- The Service Bus queue contains a message per bug update.
- A payload with a tampered body is rejected with 401; genuine deliveries return 202.
- The Teams channel receives a Boards card for a new bug and a pipeline approval card you can act on.
- GitHub app posts review and workflow notifications only for the subscribed features.
Go further
- Trigger a YAML pipeline from your monitoring tool through an Incoming WebHook service connection.
- Add a GitHub Actions workflow on
repository_dispatchand call it from the Azure Function. - Disable the webhook endpoint and observe retry behaviour and subscription disablement in History.
Source control
Protect main in Azure Repos with branch policies, build validation and branch security
LAB-D2-01
Configure a complete pull request workflow for an Azure Repos repository: two reviewers with last-pusher protection, linked work items, comment resolution, squash-only merges, a path-filtered build validation policy using a YAML pipeline, an automatically included reviewer for database changes, and branch-folder permissions that force a naming convention. Finally prove that direct pushes are blocked and that only an authorised user can bypass.
You need
- Azure DevOps organisation and a project where you are Project Administrator
- Azure CLI with the azure-devops extension (
az extension add --name azure-devops) - A second test user (or a colleague) to act as reviewer
- Git installed locally
Steps
Show solution code
# azure-pipelines.yml - used by the build validation policy (PR trigger comes from the policy)
trigger:
branches:
include: [ main ]
pr: none # ignored for Azure Repos anyway; policy drives PR builds
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
fetchDepth: 1
- task: UseDotNet@2
inputs:
packageType: sdk
version: 8.x
- script: dotnet build src --configuration Release
displayName: Build
- script: dotnet test src --configuration Release --logger trx
displayName: Test
- task: PublishTestResults@2
condition: always()
inputs:
testResultsFormat: VSTest
testResultsFiles: '**/*.trx'Check your work
az repos policy list --repository-id $REPO --branch main -o tableshows six policies, all blocking.- Direct push to main is rejected; push to
experiment/xis rejected by branch-folder security. - A src/ PR shows a running 'web-app-pr' build; a docs/ PR shows the build policy as not applicable.
- A PR touching db/ automatically adds the DBA reviewer as Required.
- Only the squash merge option is selectable in the Complete dialog.
Go further
- Move the reviewer and build rules into a cross-repo policy for the default branch of all repositories.
- Write an Azure Function that posts a
license-check/scanstatus and add a Status checks policy for it. - Add the repository policies 'Maximum file size' (50 MB) and 'File path validation' for
*.pfx.
GitHub rulesets, CODEOWNERS and a merge queue
LAB-D2-02
Protect the default branch of a GitHub repository with a ruleset that requires two approvals, code owner review, approval of the most recent push, conversation resolution, a passing CI check, signed commits and linear history; add a tag ruleset for release tags; and enable a merge queue backed by a workflow that responds to the merge_group event.
You need
- GitHub organisation (merge queue requires an organisation-owned repository; private repos need a plan that supports it)
- GitHub CLI (
gh) authenticated with admin rights on the repository - A GPG or SSH signing key configured in Git and uploaded to GitHub
- Two teams in the organisation, e.g.
platform-leadsandpayments-team
Steps
Show solution code
# .github/workflows/ci.yml
name: ci
on:
pull_request:
branches: [ main ]
merge_group:
types: [ checks_requested ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm testCheck your work
gh api repos/contoso/web-app/rulesetslists the branch and tag rulesets with enforcement 'active'.gh api repos/contoso/web-app/rules/branches/mainshows the aggregated rules applying to main.- The PR page lists 'Code owner review required' and the
buildcheck as required. - The merged commit on main is a single, verified, squash commit added by the merge queue.
- Ruleset Insights shows the rejected push attempts.
Go further
- Create an organisation ruleset that applies the same rules to all repositories with a custom property
tier=production. - Add a push ruleset that blocks files over 10 MB and paths matching
**/*.pem. - Enable secret scanning push protection and attempt to push a test token.
Tame a large repository with Git LFS, Scalar and optimised pipeline checkout
LAB-D2-03
Measure the cost of binaries in Git history, migrate them to Git LFS with a history rewrite, then use Scalar, partial clone and sparse checkout to make developer clones fast, and tune the CI checkout so builds fetch only what they need.
You need
- Git 2.38 or later (includes Scalar) and Git LFS installed
- An Azure Repos or GitHub repository you can force-push to (a throw-away copy)
- A few large binary files (e.g. 20-60 MB images or model files)
Steps
Show solution code
# Azure Pipelines - optimised checkout for the web build
steps:
- checkout: self
fetchDepth: 1
fetchTags: false
lfs: true
sparseCheckoutDirectories: src/web build
clean: true
- script: npm ci && npm run build
workingDirectory: src/web
# GitHub Actions equivalent
# - uses: actions/checkout@v4
# with:
# fetch-depth: 1
# lfs: true
# sparse-checkout: |
# src/web
# buildCheck your work
git lfs ls-fileslists every .psd/.onnx file;git show HEAD:assets/logo.psd | head -3shows a pointer.- Packed repository size after migration is a fraction of the original.
scalar listshows the registered enlistment;git statusis fast in the Scalar clone.- Pipeline log shows sparse checkout and LFS fetch; checkout time decreased.
- Pushing a 30 MB non-LFS file is rejected by the policy/ruleset.
Go further
- Set up git-fat with an rsync target for one folder and compare the workflow with Git LFS.
- Split shared code into a package in Azure Artifacts and consume it from two repos instead of a submodule.
- Add a second repository as a submodule and check it out in the pipeline with
submodules: true.
Recover lost work and purge a leaked secret from history
LAB-D2-04
Practise local and server-side recovery (reflog, reset modes, revert of a merge, cherry-pick, restoring deleted branches in Azure Repos and GitHub) and then perform a correct leaked-secret response: rotate, rewrite history with git filter-repo, force-push, clean up and prevent recurrence.
You need
- A throw-away repository in Azure Repos and one in GitHub
- Python 3 with
pip install git-filter-repo(or BFG Repo-Cleaner with Java) - Force push permission on the test repositories
- An Azure Storage account you can regenerate keys on (or a dummy token)
Steps
Show solution code
# Leaked-secret cleanup with git filter-repo
git clone --mirror https://dev.azure.com/contoso/Lab/_git/leaky leaky.git
cd leaky.git
git filter-repo --invert-paths --path config/secrets.json
# also scrub the literal value anywhere else it appears
printf 'DefaultEndpointsProtocol=https;AccountKey=abc123==>***REMOVED***\n' > ../repl.txt
git filter-repo --replace-text ../repl.txt --force
git remote add origin https://dev.azure.com/contoso/Lab/_git/leaky
git push origin --force --all
git push origin --force --tags
# Alternative with BFG (fix HEAD first with a normal commit)
# java -jar bfg.jar --delete-files secrets.json leaky.git
# cd leaky.git && git reflog expire --expire=now --all && git gc --prune=now --aggressive
# git push --forceCheck your work
- Recovered branch
feature/reportcontains all three original commits. git log --oneline mainshows a 'Revert "Merge ..."' commit; history was not rewritten.- The cherry-picked commit message includes '(cherry picked from commit ...)'.
- Fresh clones show no trace of config/secrets.json in any branch or tag.
- The old storage key no longer authenticates (rotation confirmed).
Go further
- Restore a deleted Azure Repos repository from the recycle bin with the REST API within 30 days.
- Use GitHub's repository Activity view to find a force push and restore the overwritten commit.
- Replace the storage key entirely with workload identity federation / managed identity so no secret exists to leak.
Packages, testing and pipelines
Azure Artifacts feed with upstream sources, views and promotion
LAB-D3A-01
Create a project-scoped Azure Artifacts feed that proxies nuget.org, publish an internal library from a YAML pipeline with an auto-incrementing SemVer version, and promote a validated version to the @Release view that a consumer project restores from.
You need
- Azure DevOps organization and project with Azure Repos
- A small .NET class library (Contoso.Core) and a consumer console app
- Project Administrator rights to manage feed permissions
Steps
Show solution code
trigger:
branches:
include: [main]
variables:
major: 1
minor: 0
patch: $[counter(format('{0}.{1}', variables['major'], variables['minor']), 0)]
packageVersion: $(major).$(minor).$(patch)
feedUrl: https://pkgs.dev.azure.com/<org>/<project>/_packaging/core-libs/nuget/v3/index.json
name: $(major).$(minor).$(patch)
pool:
vmImage: ubuntu-latest
steps:
- task: UseDotNet@2
inputs:
version: 8.x
- task: NuGetAuthenticate@1
- script: dotnet restore --configfile nuget.config
- script: dotnet build -c Release --no-restore
- script: >
dotnet pack src/Contoso.Core -c Release --no-build
-o $(Build.ArtifactStagingDirectory) -p:PackageVersion=$(packageVersion)
- script: >
dotnet nuget push $(Build.ArtifactStagingDirectory)/*.nupkg
--source $(feedUrl) --api-key AzureArtifacts
displayName: Push $(packageVersion) to core-libsCheck your work
- Feed shows Contoso.Core 1.0.0 and 1.0.1 in @Local and 1.0.1 in @Release
- Polly appears in the feed with an upstream source indicator
- Consumer restore succeeds from core-libs@Release and cannot see 1.0.0
- Run numbers equal the package versions
Go further
- Add a second stage that runs integration tests and promotes the package via REST using $(System.AccessToken)
- Remove the Feed Publisher role from the build service and observe the 403 error
- Replace counter() with GitVersion and conventional +semver commit messages
Publish npm packages and container images to GitHub Packages
LAB-D3A-02
Use GitHub Actions with GITHUB_TOKEN to publish a scoped npm package and a container image to GitHub Packages on each release, with least-privilege permissions and a SemVer version taken from the release tag.
You need
- GitHub organization (or user) and repository
- A Node.js library with package.json named @<owner>/greeter
- A Dockerfile for a small web app
Steps
Show solution code
name: release
on:
release:
types: [published]
permissions:
contents: read
jobs:
npm:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://npm.pkg.github.com
- run: npm ci
- run: npm version "${GITHUB_REF_NAME#v}" --no-git-tag-version
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- id: v
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/greeter-web:${{ steps.v.outputs.version }}
ghcr.io/${{ github.repository_owner }}/greeter-web:sha-${{ github.sha }}Check your work
- npm package @<owner>/greeter version 1.2.0 visible under Packages
- ghcr.io image has tags 1.2.0 and sha-<commit>
- Removing
packages: writemakes the publish fail with 403
Go further
- Add actions/attest-build-provenance to the image job
- Add a Dependabot config for npm and docker ecosystems
- Compare with publishing the same npm package to an Azure Artifacts feed
Tests, coverage and quality gates in Azure Pipelines
LAB-D3A-03
Build a PR validation pipeline that runs unit tests, publishes results and Cobertura coverage even on failure, enforces 80 percent diff coverage on pull requests through branch policy, and fails the build when overall coverage drops below a threshold.
You need
- Azure Repos Git repository with a .NET 8 solution and an xUnit test project
- Permission to edit branch policies on main
- Build Quality Checks extension installed (optional for step 8)
Steps
Show solution code
trigger:
branches:
include: [main]
pool:
vmImage: ubuntu-latest
steps:
- task: UseDotNet@2
inputs:
version: 8.x
- script: dotnet build -c Release
displayName: Build
- task: DotNetCoreCLI@2
displayName: Unit tests
inputs:
command: test
projects: 'tests/**/*.Tests.csproj'
arguments: >-
-c Release --no-build --collect "XPlat Code Coverage"
--results-directory $(Agent.TempDirectory)/tr
- task: PublishCodeCoverageResults@2
displayName: Publish coverage
condition: succeededOrFailed()
inputs:
summaryFileLocation: '$(Agent.TempDirectory)/tr/**/coverage.cobertura.xml'
- task: BuildQualityChecks@10
displayName: Coverage threshold
inputs:
checkCoverage: true
coverageFailOption: fixed
coverageType: lines
coverageThreshold: '70'Check your work
- Tests tab shows results for passing and failing runs
- Code Coverage tab shows the HTML report
- PR with low diff coverage is blocked by the required status
- Deleting tests fails the Coverage threshold step
Go further
- Add SonarQube Cloud analysis and require its PR status
- Split tests across 3 agents with strategy: parallel and VSTest on Windows
- Add an Azure Load Testing stage with a fail criterion on p90 latency
Triggers: CI filters, PR validation, schedules and pipeline completion
LAB-D3A-04
Configure a CI pipeline with branch, path and tag filters and batching, a nightly scheduled run that always executes, and a downstream CD pipeline that starts only when the CI pipeline completes on main with a specific run tag.
You need
- Azure DevOps project with a GitHub or Azure Repos repository
- Two YAML files: ci.yml and cd.yml
Steps
Show solution code
# ---------- ci.yml ----------
trigger:
batch: true
branches:
include: [main, release/*]
paths:
include: [src/*]
exclude: [docs/*]
tags:
include: ['v*']
pr:
branches:
include: [main]
schedules:
- cron: '0 1 * * *'
displayName: Nightly security scan
branches:
include: [main]
always: true
pool:
vmImage: ubuntu-latest
steps:
- script: echo build > $(Build.ArtifactStagingDirectory)/app.txt
- publish: $(Build.ArtifactStagingDirectory)
artifact: drop
- script: echo "##vso[build.addbuildtag]release-candidate"
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
# ---------- cd.yml ----------
trigger: none
pr: none
resources:
pipelines:
- pipeline: ci
source: Orders-CI
trigger:
branches:
include: [main]
tags: [release-candidate]
pool:
vmImage: ubuntu-latest
steps:
- download: ci
artifact: drop
- script: cat $(Pipeline.Workspace)/ci/drop/app.txtCheck your work
- Docs-only pushes do not trigger Orders-CI
- Tag push v1.0.0 triggers Orders-CI
- Orders-CD runs only after main runs tagged release-candidate
- Scheduled runs list shows the nightly entry
Go further
- Add a stages filter to the pipeline resource trigger
- Recreate the same flow in GitHub Actions with workflow_run and schedule
- Trigger a GitHub workflow from curl using repository_dispatch
Multi-stage YAML with fan-out/fan-in, outputs, matrix and deployment strategies
LAB-D3A-05
Build a multi-stage pipeline that runs a test matrix, passes an image tag between jobs and stages with output variables, fans out to parallel quality stages, and deploys with a runOnce deployment job to an environment.
You need
- Azure DevOps project
- An environment named
test(no checks yet)
Steps
Show solution code
stages:
- stage: Build
jobs:
- job: build
pool:
vmImage: ubuntu-latest
steps:
- bash: echo "##vso[task.setvariable variable=imageTag;isOutput=true]$(Build.BuildId)"
name: setTag
- job: unit
pool:
vmImage: $(img)
strategy:
maxParallel: 2
matrix:
linux: { img: ubuntu-latest }
windows: { img: windows-latest }
mac: { img: macos-latest }
steps:
- script: echo testing on $(img)
- stage: Test
dependsOn: Build
jobs:
- job: integration
steps:
- script: echo integration
- stage: Security
dependsOn: Build
jobs:
- job: scan
steps:
- script: echo scanning
- stage: Deploy
dependsOn: [Test, Security]
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- deployment: web
variables:
tag: $[ stageDependencies.Build.build.outputs['setTag.imageTag'] ]
environment: test
strategy:
runOnce:
deploy:
steps:
- download: none
- script: echo deploying image tag $(tag)
- stage: Notify
dependsOn: [Test, Security, Deploy]
condition: failed()
jobs:
- job: alert
pool: server
steps:
- task: Delay@1
inputs:
delayForMinutes: '0'Check your work
- Stage graph shows fan-out after Build and fan-in at Deploy
- Deploy log prints the BuildId produced in Build
- Matrix shows three legs with maxParallel 2
- Notify runs only when a stage fails
Go further
- Generate the matrix dynamically from a JSON output variable
- Add a container job with a Redis service container to the Test stage
- Convert the Deploy stage to a canary strategy against an AKS environment resource
Governed templates, variable groups with Key Vault and environment checks
LAB-D3A-06
Create a shared templates repository with a versioned stage template and an extends template, link a variable group to Azure Key Vault through a workload identity federation service connection, and protect the prod environment with approvals, branch control, business hours, exclusive lock and a Required template check.
You need
- Azure subscription with a Key Vault containing secret
SqlPassword - Azure Resource Manager service connection using workload identity federation (
sc-prod-wif) with Key Vault Secrets User on the vault - Two repos:
Platform/pipeline-templatesand an application repo
Steps
Show solution code
# ---- pipeline-templates/stages/deploy.yml ----
parameters:
- name: environment
type: string
values: [test, prod]
stages:
- stage: Deploy_${{ parameters.environment }}
variables:
- group: orders-kv
jobs:
- deployment: app
environment: ${{ parameters.environment }}
pool:
vmImage: ubuntu-latest
strategy:
runOnce:
deploy:
steps:
- script: ./deploy.sh
env:
SQL_PASSWORD: $(SqlPassword)
# ---- pipeline-templates/secure-pipeline.yml ----
parameters:
- name: buildSteps
type: stepList
default: []
stages:
- stage: Build
jobs:
- job: build
pool:
vmImage: ubuntu-latest
steps:
- script: echo mandatory secret scan here
- ${{ parameters.buildSteps }}
- script: echo mandatory SBOM generation here
- template: stages/deploy.yml
parameters:
environment: prod
# ---- application repo: azure-pipelines.yml ----
resources:
repositories:
- repository: templates
type: git
name: Platform/pipeline-templates
ref: refs/tags/v1.0.0
extends:
template: secure-pipeline.yml@templates
parameters:
buildSteps:
- script: dotnet build -c ReleaseCheck your work
- Prod stage waits for approval and respects business hours
- Feature-branch runs fail Branch control
- A pipeline that does not extend the template is blocked by Required template
- SqlPassword is masked in logs
Go further
- Add an Invoke REST API check that queries a mock change-management endpoint
- Add a Query Azure Monitor alerts check for the production app
- Block inline
scriptsteps in buildSteps using${{ each }}validation
GitHub Actions: reusable workflow, composite action and protected environments
LAB-D3A-07
Create a composite action for setup, a reusable deployment workflow that targets environments with protection rules, and a caller workflow that deploys to staging and production with OIDC to Azure and a concurrency group.
You need
- GitHub repository (public, or private on GitHub Enterprise Cloud for reviewers)
- Entra ID app registration with federated credentials for environment:staging and environment:production, and RBAC on the target Web Apps
- Two Azure Web Apps: orders-staging and orders-prod
Steps
Show solution code
# ---- .github/actions/setup-node-cache/action.yml ----
name: Setup Node with cache
inputs:
node-version:
default: '22'
runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: npm
- run: npm ci
shell: bash
# ---- .github/workflows/deploy.yml ----
on:
workflow_call:
inputs:
environment: { type: string, required: true }
app-name: { type: string, required: true }
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
concurrency:
group: deploy-${{ inputs.environment }}
cancel-in-progress: false
steps:
- uses: actions/download-artifact@v4
with: { name: web, path: web }
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- uses: azure/webapps-deploy@v3
with:
app-name: ${{ inputs.app-name }}
package: web
# ---- .github/workflows/ci-cd.yml ----
on:
push:
branches: [main]
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node-cache
- run: npm run build && npm test
- uses: actions/upload-artifact@v4
with: { name: web, path: dist }
staging:
needs: build
uses: ./.github/workflows/deploy.yml
with: { environment: staging, app-name: orders-staging }
production:
needs: staging
uses: ./.github/workflows/deploy.yml
with: { environment: production, app-name: orders-prod }Check your work
- Production job waits for reviewer approval and the wait timer
- Feature-branch runs cannot deploy to production
- azure/login succeeds without any client secret (OIDC)
- Only one production deployment runs at a time
Go further
- Move deploy.yml to a central repo and call it with @v1 from several repos
- Require the workflow through an organization ruleset
- Add a custom deployment protection rule app
Deployments, IaC and maintenance
Zero-downtime App Service release with a staging slot, sticky settings and swap
LAB-D3B-01
Build a multi-stage YAML pipeline that deploys a web app to a staging slot, runs a smoke test against it, swaps it into production behind an environment approval, and swaps back automatically if the post-swap health check fails. Along the way you will prove that slot-specific settings stay with their slot.
You need
- Azure subscription and an Azure DevOps project
- ARM service connection using workload identity federation (sc-demo-wif)
- A simple web app with a /health endpoint in Azure Repos or GitHub
- Azure CLI 2.60+ locally
Steps
Show solution code
trigger: { branches: { include: [ main ] } }
variables:
app: lab-shop-web
rg: rg-lab
stages:
- stage: Build
jobs:
- job: Build
pool: { vmImage: ubuntu-latest }
steps:
- script: dotnet publish src/Web -c Release -o $(Build.ArtifactStagingDirectory)/web
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.ArtifactStagingDirectory)/web
includeRootFolder: false
archiveFile: $(Build.ArtifactStagingDirectory)/web.zip
- publish: $(Build.ArtifactStagingDirectory)/web.zip
artifact: drop
- stage: Staging
dependsOn: Build
jobs:
- job: DeploySlot
pool: { vmImage: ubuntu-latest }
steps:
- download: current
artifact: drop
- task: AzureWebApp@1
inputs:
azureSubscription: sc-demo-wif
appType: webAppLinux
appName: $(app)
deployToSlotOrASE: true
resourceGroupName: $(rg)
slotName: staging
package: $(Pipeline.Workspace)/drop/web.zip
- script: >
curl --fail --retry 10 --retry-delay 6
https://$(app)-staging.azurewebsites.net/health
- stage: Production
dependsOn: Staging
jobs:
- deployment: Swap
pool: { vmImage: ubuntu-latest }
environment: lab-prod
strategy:
runOnce:
deploy:
steps:
- task: AzureAppServiceManage@0
inputs:
azureSubscription: sc-demo-wif
Action: Swap Slots
WebAppName: $(app)
ResourceGroupName: $(rg)
SourceSlot: staging
postRouteTraffic:
steps:
- script: curl --fail --retry 5 https://$(app).azurewebsites.net/health
on:
failure:
steps:
- task: AzureAppServiceManage@0
inputs:
azureSubscription: sc-demo-wif
Action: Swap Slots
WebAppName: $(app)
ResourceGroupName: $(rg)
SourceSlot: stagingCheck your work
- After the swap, production shows
ENV_NAME=production(sticky) butBUILD_COLOR=green(moved with the content). - The run history shows the approval on
lab-prodand the deployment recorded on the environment. - With a broken health endpoint the failure hook runs and production serves the previous version again.
Go further
- Replace the plain swap with swap-with-preview (
az webapp deployment slot swap --action previewthen--action swap) and validate between phases. - Configure
WEBSITE_SWAP_WARMUP_PING_PATH=/healthand measure first-request latency. - Route 10 percent of traffic to staging with
az webapp traffic-routing set.
Progressive exposure with Azure App Configuration feature flags
LAB-D3B-02
Gate a new feature in an ASP.NET Core app behind an Azure App Configuration feature flag, roll it out with the Targeting filter (named users, a group and a default percentage), use labels to separate environments, and toggle the flag from a pipeline after a successful deployment.
You need
- Azure subscription
- .NET 8 SDK
- An App Service or local dev environment with DefaultAzureCredential access
- Azure DevOps pipeline with a workload identity federation service connection
Steps
Show solution code
// Program.cs
using Azure.Identity;
using Microsoft.FeatureManagement;
var builder = WebApplication.CreateBuilder(args);
var label = builder.Environment.EnvironmentName.ToLowerInvariant();
builder.Configuration.AddAzureAppConfiguration(o =>
o.Connect(new Uri(builder.Configuration["AppConfig:Endpoint"]!),
new DefaultAzureCredential())
.UseFeatureFlags(ff => { ff.Select("*", label);
ff.SetRefreshInterval(TimeSpan.FromSeconds(30)); }));
builder.Services.AddAzureAppConfiguration();
builder.Services.AddHttpContextAccessor();
builder.Services.AddFeatureManagement().WithTargeting();
var app = builder.Build();
app.UseAzureAppConfiguration();
app.MapGet("/", async (IFeatureManager fm) =>
await fm.IsEnabledAsync("NewCheckout") ? "NEW checkout" : "classic checkout");
app.Run();
# pipeline step (AzureCLI@2 inline script)
# az appconfig feature enable --name appcs-lab --feature NewCheckout --label prod --yesCheck your work
- With label
devevery request returns NEW checkout; withprodonly pilot users, BetaTesters and about 10 percent of other users do. - The same user consistently gets the same answer across refreshes (Targeting is sticky; Percentage would not be).
- Disabling the flag in the portal changes behaviour within ~30 seconds without a restart.
Go further
- Convert the flag to a variant flag (
Small/Largebutton) and send telemetry to Application Insights for an A/B comparison. - Add a TimeWindow filter that turns a banner on only during a sale weekend.
- Create an App Configuration snapshot for the release and reference it from the app.
Canary deployment to AKS and revision traffic splitting in Container Apps
LAB-D3B-03
Deploy a containerized API with a YAML canary deployment job on AKS (baseline + canary, health check, promote or reject), then reproduce the same pattern on Azure Container Apps using multiple revision mode, revision labels and traffic weights.
You need
- AKS cluster with ACR attached (
az aks update --attach-acr) - Azure DevOps environment
prod-akswith a Kubernetes resource (namespaceshop) - A Container Apps environment
- Dockerfile and Kubernetes manifests
Steps
Show solution code
- stage: DeployAKS
jobs:
- deployment: Canary
pool: { vmImage: ubuntu-latest }
environment: prod-aks.shop
strategy:
canary:
increments: [10]
deploy:
steps:
- checkout: self
- task: KubernetesManifest@1
inputs:
action: deploy
strategy: canary
percentage: $(strategy.increment)
manifests: k8s/deployment.yml
containers: myacr.azurecr.io/shop-api:$(Build.BuildId)
postRouteTraffic:
pool: server
steps:
- task: Delay@1
inputs: { delayForMinutes: '5' } # bake time
on:
failure:
steps:
- checkout: self
- task: KubernetesManifest@1
inputs: { action: reject, strategy: canary, manifests: k8s/deployment.yml }
success:
steps:
- checkout: self
- task: KubernetesManifest@1
inputs: { action: promote, strategy: canary, manifests: k8s/deployment.yml }Check your work
kubectl get deploy -n shopshows baseline and canary deployments during the bake time and only the stable deployment after promote/reject.- The environment's deployment history lists each run and its commits.
az containerapp ingress traffic showreports the expected revision weights.
Go further
- Replace Delay@1 with an environment check Query Azure Monitor alerts on error rate.
- Use Flux GitOps instead of push deployment and compare the trade-offs.
Bicep pipeline with linting, PSRule, what-if on PR and a deployment stack
LAB-D3B-04
Create an IaC pipeline in which every pull request lints the Bicep code, runs PSRule for Azure and posts a what-if, and every merge to main deploys through an approved environment as a deployment stack that deletes removed resources and blocks portal changes.
You need
- Azure subscription with Owner or User Access Administrator on a test RG
- Two WIF service connections (test and prod)
- PSRule extension installed in the Azure DevOps organization
- Bicep CLI (az bicep install)
Steps
Show solution code
trigger: { branches: { include: [ main ] }, paths: { include: [ infra/* ] } }
pr: { branches: { include: [ main ] }, paths: { include: [ infra/* ] } }
stages:
- stage: Validate
jobs:
- job: Validate
pool: { vmImage: ubuntu-latest }
steps:
- script: az bicep build --file infra/main.bicep --stdout > /dev/null
displayName: Bicep lint
- task: ps-rule-assert@2
inputs: { modules: PSRule.Rules.Azure, inputPath: infra/ }
- task: AzureCLI@2
displayName: what-if
inputs:
azureSubscription: sc-test-wif
scriptType: bash
scriptLocation: inlineScript
inlineScript: >
az deployment group what-if -g rg-lab-test
-f infra/main.bicep -p infra/test.bicepparam
- stage: Deploy
dependsOn: Validate
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- deployment: Stack
pool: { vmImage: ubuntu-latest }
environment: prod-infra
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: AzureCLI@2
retryCountOnTaskFailure: 2
inputs:
azureSubscription: sc-prod-wif
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
az stack group create --name lab-stack -g rg-lab-prod \
--template-file infra/main.bicep --parameters infra/prod.bicepparam \
--action-on-unmanage deleteResources \
--deny-settings-mode denyWriteAndDelete --yesCheck your work
- PR builds fail on linter errors or PSRule failures and show what-if output.
az stack group show -g rg-lab-prod -n lab-stacklists managed resources and deny settings.- Portal deletion is denied; removal from code deletes the resource.
Go further
- Publish a module to a private ACR Bicep registry and consume it with
br:. - Add a scheduled nightly run that executes what-if and fails if changes are detected (drift detection).
- Rewrite the same infra in Terraform with an azurerm backend using OIDC.
Enforce in-guest configuration with Azure Machine Configuration and set up Azure Deployment Environments
LAB-D3B-05
Package a PowerShell DSC configuration as a Machine Configuration package, publish it as an Azure Policy with ApplyAndAutoCorrect, remediate existing VMs, and then give developers self-service environments from a catalog with Azure Deployment Environments.
You need
- Azure subscription with Resource Policy Contributor and Owner on a test RG
- A Windows Server VM (or an Arc-enabled server)
- PowerShell 7 with the GuestConfiguration and PSDesiredStateConfiguration modules
- A GitHub or Azure Repos repo for the ADE catalog
Steps
Show solution code
Configuration WebServer {
Import-DscResource -ModuleName PSDscResources
Node localhost {
WindowsFeature IIS { Name = 'Web-Server'; Ensure = 'Present' }
Service W3SVC {
Name = 'W3SVC'; State = 'Running'; StartupType = 'Automatic'
DependsOn = '[WindowsFeature]IIS'
}
}
}
WebServer -OutputPath ./out
New-GuestConfigurationPackage -Name WebServer -Configuration ./out/localhost.mof `
-Type AuditAndSet -Force
Get-GuestConfigurationPackageComplianceStatus -Path ./WebServer.zip
# after upload to storage:
New-GuestConfigurationPolicy -PolicyId (New-Guid) -ContentUri $uri `
-DisplayName 'IIS running' -Description 'IIS installed and running' `
-Path ./policies -Platform Windows -PolicyVersion 1.0.0 -Mode ApplyAndAutoCorrectCheck your work
- Azure Policy shows the VM as compliant with per-resource reasons.
- The stopped service is started again automatically (auto-correct).
- The developer portal lists the WebApp definition and the created environment deploys into its own resource group with the expiration date set.
Go further
- Onboard an on-premises server with Azure Arc and observe the same policy applying.
- Add a Terraform environment definition using a custom runner image.
- Create environments per pull request from a pipeline and delete them on PR completion.
Optimize, govern retention for, and migrate a classic pipeline to YAML
LAB-D3B-06
Take an existing classic build and release pipeline, export the build to YAML, map the release stages to deployment jobs and environments, then optimize the result with caching, shallow fetch and test slicing, enable flaky test detection, and add a retention lease for production runs.
You need
- Azure DevOps project with a classic build and classic release pipeline
- A .NET solution with unit tests
- Project Administrator rights
Steps
Show solution code
trigger:
batch: true
branches: { include: [ main ] }
paths: { exclude: [ docs/* ] }
pr: [ main ]
variables:
- group: shop-common
- name: NUGET_PACKAGES
value: $(Pipeline.Workspace)/.nuget/packages
stages:
- stage: Build
jobs:
- job: Test
strategy: { parallel: 3 }
pool: { vmImage: windows-latest }
steps:
- checkout: self
fetchDepth: 1
- task: Cache@2
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json'
restoreKeys: 'nuget | "$(Agent.OS)"'
path: $(NUGET_PACKAGES)
- script: dotnet build -c Release
- task: VSTest@3
inputs:
testAssemblyVer2: '**/bin/Release/**/*Tests.dll'
distributionBatchType: basedOnExecutionTime
- stage: Prod
dependsOn: Build
jobs:
- deployment: Deploy
pool: { vmImage: ubuntu-latest }
environment: shop-prod # approvals + Azure Monitor check moved here
strategy:
runOnce:
deploy:
steps:
- script: echo "deploy"
- pwsh: |
$body = ConvertTo-Json @(@{ daysValid = 365
definitionId = $(System.DefinitionId)
ownerId = "User:$(Build.RequestedForId)"; protectPipeline = $false
runId = $(Build.BuildId) })
$uri = "$(System.CollectionUri)$(System.TeamProject)" +
"/_apis/build/retention/leases?api-version=7.1"
Invoke-RestMethod -Method POST -ContentType application/json -Body $body `
-Uri $uri -Headers @{ Authorization = "Bearer $(System.AccessToken)" }Check your work
- Pipeline duration report shows a lower average after caching and slicing; cache hits appear in the Cache@2 post-job log.
- The Tests tab lists flaky tests separately and they no longer fail the run.
- The production run shows a retention lease (Retained) in its run details.
- New classic pipelines cannot be created in the project.
Go further
- Build a Power BI report over the Analytics
PipelineRunsentity with failure rate per week. - Move the build to a Managed DevOps Pool with stateful agents and compare duration and cost.
- Use GitHub Actions Importer to dry-run a migration of the same pipeline to GitHub.
Security and compliance
Deploy from GitHub Actions to Azure with OIDC (no secrets)
LAB-D4-01
Create a user-assigned managed identity with a federated credential that trusts a GitHub environment, grant it least-privilege RBAC on a resource group, and deploy with azure/login using OpenID Connect so no Azure credential is stored in GitHub.
You need
- Azure subscription with rights to create identities and role assignments
- A GitHub repository you administer
- Azure CLI 2.60+
Steps
Show solution code
name: oidc-deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: prod
steps:
- 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 storage account create -g rg-oidc-lab \
-n stoidc$RANDOM --sku Standard_LRSCheck your work
- The run log shows 'Login successful' with no client secret configured
- Activity log on rg-oidc-lab shows the operation by the managed identity
- Repository Settings > Secrets contains no Azure credentials
Go further
- Add a second federated credential for
pull_requestwith a Reader-only identity for what-if previews - Replace the managed identity with an app registration and compare steps
Convert an Azure DevOps service connection to workload identity federation and protect it with checks
LAB-D4-02
Create (or convert) an Azure Resource Manager service connection that uses workload identity federation, scope it to a resource group, and protect it with pipeline permissions, branch control and an approval check.
You need
- Azure DevOps project with Project Administrator rights
- Azure subscription Owner or User Access Administrator on a resource group
- A YAML pipeline in Azure Repos
Steps
Show solution code
trigger: none
pool:
vmImage: ubuntu-latest
steps:
- task: AzureCLI@2
inputs:
azureSubscription: prod-arm-wif
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
az account show --query '{sub:id, user:user.name}' -o table
az group show -n rg-wif-lab -o tableCheck your work
- Feature-branch run is blocked by the branch control check
- Main-branch run waits for approval, then shows the subscription details
- The app registration has no client secrets listed
Go further
- Add a Required template check so only pipelines extending
templates/secure-deploy.ymlcan use the connection - Create the federated credential manually on a user-assigned managed identity and a manual WIF connection
Consume Key Vault secrets and secure files safely in Azure Pipelines
LAB-D4-03
Store secrets in an RBAC-enabled Key Vault with purge protection, read them with AzureKeyVault@2 and a Key Vault-linked variable group, use a secure file, and prove that secrets are masked and only reach steps via explicit env mapping.
You need
- Completed LAB-D4-02 (service connection prod-arm-wif)
- Azure CLI
- A test .pfx file (self-signed is fine)
Steps
Show solution code
trigger: none
pool:
vmImage: ubuntu-latest
variables:
- group: kv-lab
steps:
- task: AzureKeyVault@2
inputs:
azureSubscription: prod-arm-wif
KeyVaultName: kv-lab-unique
SecretsFilter: SqlPassword
- task: DownloadSecureFile@1
name: cert
inputs:
secureFile: lab-cert.pfx
- bash: |
echo "sql length: ${#SQL_PWD}"
echo "api length: ${#API_KEY}"
echo "masked value: $SQL_PWD"
ls -l "$CERT_PATH"
env:
SQL_PWD: $(SqlPassword)
API_KEY: $(ApiKey)
CERT_PATH: $(cert.secureFilePath)Check your work
- Log shows non-zero lengths and
masked value: *** - The .pfx is listed under the agent temp directory during the job
- Removing the env mapping makes the variables empty in the script
Go further
- Add a step that sets a runtime secret with
##vso[task.setvariable variable=t;issecret=true]and verify masking - Turn on the vault firewall and observe Microsoft-hosted agents failing; fix with a self-hosted or Managed DevOps Pool agent in the VNet
Enable GitHub Advanced Security: CodeQL, push protection, Dependabot and dependency review
LAB-D4-04
On a GitHub repository, enable secret scanning with push protection, configure CodeQL advanced setup, add dependabot.yml version updates, and gate pull requests with dependency review including a license policy.
You need
- A public GitHub repository (GHAS features are free on public repos) or GHAS licenses
- A small Node.js or .NET sample app
Steps
Show solution code
name: dependency-review
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/dependency-review-action@v4
with:
fail-on-severity: high
deny-licenses: GPL-3.0, AGPL-3.0
comment-summary-in-pr: alwaysCheck your work
- Push with the test secret is rejected by push protection
- Dependency review fails the PR, listing the vulnerability and license
- Dependabot opens version update PRs on schedule
Go further
- Add a container job running CodeQL inside
mcr.microsoft.com/dotnet/sdk:8.0 - Add Trivy image scanning and upload SARIF with category
container
Advanced Security for Azure DevOps and Defender for Cloud DevOps security
LAB-D4-05
Enable GitHub Secret Protection and Code Security for an Azure Repos repository, run CodeQL and dependency scanning in a pipeline, gate PRs on new high/critical alerts, then connect the organization to Defender for Cloud and review DevOps posture and MSDO findings.
You need
- Azure DevOps org (Project Collection Administrator or 'Advanced Security: manage settings')
- Billing configured for Advanced Security
- Azure subscription with Defender for Cloud access (Security Admin)
Steps
Show solution code
trigger:
branches:
include: [main]
pool:
vmImage: windows-latest
steps:
- task: AdvancedSecurity-Codeql-Init@1
inputs:
languages: csharp
querysuite: security-extended
- task: AdvancedSecurity-Codeql-Autobuild@1
- task: AdvancedSecurity-Dependency-Scanning@1
- task: AdvancedSecurity-Codeql-Analyze@1
- task: MicrosoftSecurityDevOps@1
inputs:
categories: IaC
artifactName: CodeAnalysisLogsCheck your work
- Advanced Security tab shows CodeQL and dependency alerts
- A PR introducing a new high vulnerability is blocked by the status check
- Defender for Cloud DevOps security lists the repository and recommendations
- KQL over AzureDevOpsAuditing returns recent events
Go further
- Switch to code scanning default setup for the whole organization and compare
- Enable Defender CSPM and inspect PR annotations for IaC findings
Instrumentation
Instrument a web API with Application Insights (OpenTelemetry) and a standard availability test
LAB-D5-01
Create a Log Analytics workspace and a workspace-based Application Insights resource with Bicep, instrument a small ASP.NET Core (or Python) API with the Azure Monitor OpenTelemetry Distro, deploy it to App Service with the connection string as an app setting, add a standard availability test from five locations, and explore Live Metrics, Application Map, Performance and Failures.
You need
- Azure subscription with Contributor on a resource group
- Azure CLI 2.60+ with Bicep
- .NET 8 SDK or Python 3.11
- A sample web API project (dotnet new webapi) with a /api/slow and /api/fail endpoint
Steps
Show solution code
// monitor.bicep
param location string = resourceGroup().location
param webAppUrl string
resource law 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
name: 'law-d5-lab'
location: location
properties: { sku: { name: 'PerGB2018' }, retentionInDays: 30 }
}
resource appi 'Microsoft.Insights/components@2020-02-02' = {
name: 'appi-d5-lab'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: law.id // workspace-based
IngestionMode: 'LogAnalytics'
}
}
resource webtest 'Microsoft.Insights/webtests@2022-06-15' = {
name: 'avail-orders-home'
location: location
tags: { 'hidden-link:${appi.id}': 'Resource' }
properties: {
SyntheticMonitorId: 'avail-orders-home'
Name: 'orders-home'
Kind: 'standard'
Enabled: true
Frequency: 300
Timeout: 30
RetryEnabled: true
Locations: [
{ Id: 'emea-nl-ams-azr' }, { Id: 'emea-gb-db3-azr' }, { Id: 'us-va-ash-azr' }
{ Id: 'apac-sg-sin-azr' }, { Id: 'emea-fr-pra-edge' }
]
Request: { RequestUrl: '${webAppUrl}/', HttpVerb: 'GET', ParseDependentRequests: false }
ValidationRules: {
ExpectedHttpStatusCode: 200
SSLCheck: true
SSLCertRemainingLifetimeCheck: 14
}
}
}
output connectionString string = appi.properties.ConnectionStringCheck your work
- Application Map shows orders-api and the example.com dependency with non-zero call counts.
- Performance shows P50/P95/P99 for GET /api/slow, with P95 well above P50.
- Failures lists the exception type thrown by /api/fail with roughly 30% failure rate.
- Availability shows results from five locations every five minutes.
- AppRequests in the workspace contains rows with AppRoleName == 'orders-api'.
Go further
- Enable Microsoft Entra ID authentication for ingestion (DisableLocalAuth: true) and grant the web app's managed identity the Monitoring Metrics Publisher role.
- Set a fixed sampling ratio of 0.5 and confirm sum(ItemCount) still matches your request volume.
- Add a custom span and a custom metric with the OpenTelemetry API and find them in AppDependencies and AppMetrics.
Wire Azure Monitor alerts into Azure Pipelines, GitHub Actions and chat
LAB-D5-02
Build an end-to-end feedback loop: a log search alert with an action group, an alert processing rule for maintenance windows, a YAML pipeline whose prod environment is protected by the Query Azure Monitor alerts check and that writes release annotations, Teams/Slack notifications for pipeline and workflow failures, and automatic Azure Boards bugs created from alerts.
You need
- Completed LAB-D5-01 (App Service + Application Insights)
- Azure DevOps project with an Azure Resource Manager service connection using workload identity federation
- A GitHub repository with Actions enabled
- A Microsoft Teams or Slack workspace where you can install apps
Steps
Show solution code
# azure-pipelines.yml
trigger: { branches: { include: [ main ] } }
pool: { vmImage: ubuntu-latest }
variables:
azureSub: 'sc-d5-wif' # ARM service connection (workload identity federation)
rg: 'rg-d5-lab'
appi: 'appi-d5-lab'
stages:
- stage: Build
jobs:
- job: build
steps:
- script: dotnet publish -c Release -o $(Build.ArtifactStagingDirectory)/app
- publish: $(Build.ArtifactStagingDirectory)/app
artifact: app
- stage: Prod
dependsOn: Build
jobs:
- deployment: deploy
environment: prod # protected by 'Query Azure Monitor alerts' check
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
inputs: { azureSubscription: $(azureSub), appName: 'app-d5-lab',
package: '$(Pipeline.Workspace)/app' }
- task: AzureCLI@2
displayName: Release annotation
inputs:
azureSubscription: $(azureSub)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
id=$(az monitor app-insights component show -g $(rg) -a $(appi) \
--query id -o tsv)
body=$(jq -n --arg i "$(uuidgen)" --arg n "$(Build.BuildNumber)" \
--arg t "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg b "$(Build.BuildId)" \
'{Id:$i, AnnotationName:$n, EventTime:$t, Category:"Deployment",
Properties:({ReleaseName:$n, BuildId:$b}|tostring)}')
az rest --method put --body "$body" \
--uri "$id/Annotations?api-version=2015-05-01"Check your work
- With an active Sev1 alert, the Prod stage shows the check as 'evaluating' and does not start.
- After the alert resolves, the check passes and the deployment runs.
- Metrics explorer shows a deployment annotation at the deployment time.
- A Bug is created in Azure Boards when the alert fires (if the Logic App receiver is configured).
- The chat channel receives messages for a failed pipeline stage and a failed GitHub workflow.
- No notifications are sent during the alert processing rule's maintenance window, while alerts still appear in Alerts.
Go further
- Convert the deployment to a canary strategy and run a KQL health query in postRouteTraffic with
az monitor app-insights query, failing the job if the failure rate exceeds 2 percent. - Implement the same alert gate for GitHub Actions with a custom deployment protection rule.
Monitor VMs, AKS, storage and network with Azure Monitor insights
LAB-D5-03
Onboard a Linux VM to VM Insights with Azure Monitor Agent and a DCR (via Azure Policy), enable Managed Prometheus, Container Insights and Azure Managed Grafana on an AKS cluster, review Storage insights, and create a Connection Monitor test - then inspect CPU, memory, disk and network indicators for each.
You need
- Azure subscription (Owner or Contributor + Resource Policy Contributor)
- Log Analytics workspace law-d5-lab from LAB-D5-01
- Azure CLI with the aks-preview extension not required
Steps
Show solution code
// Useful verification queries
// VM Insights: CPU, memory and disk latency for vm-d5 in the last hour
InsightsMetrics
| where TimeGenerated > ago(1h) and Computer startswith "vm-d5"
| where (Namespace == "Processor" and Name == "UtilizationPercentage")
or (Namespace == "Memory" and Name == "AvailableMB")
or (Namespace == "LogicalDisk" and Name in ("ReadLatencyMs", "WriteLatencyMs"))
| summarize avg(Val) by Namespace, Name, bin(TimeGenerated, 5m)
| render timechart
// AKS: pods with the most error lines
ContainerLogV2
| where TimeGenerated > ago(1h) and LogLevel in ("error", "critical")
| summarize Errors = count() by PodNamespace, PodName
| top 10 by Errors
// Storage: failed blob operations by status
StorageBlobLogs
| where TimeGenerated > ago(1d) and StatusCode >= 400
| summarize count() by OperationName, StatusTextCheck your work
- VM Insights performance charts show the CPU spike from stress-ng and disk latency from fio.
- InsightsMetrics and Heartbeat contain rows for vm-d5.
- Grafana dashboards display node and pod CPU/memory from the Azure Monitor workspace.
- ContainerLogV2 contains records with PodName and PodNamespace.
- StorageBlobLogs receives records after you upload/download a blob.
- Connection Monitor shows round-trip time and checks failed percent for the test group.
Go further
- Enable the Dependency agent and use the VM Insights Map to view vm-d5's outbound connections.
- Create a Prometheus alert rule group that fires when a pod restarts more than 3 times in 15 minutes.
- Add a transformKql to the VM DCR that drops syslog messages containing 'healthcheck'.
KQL drill: 18 query exercises with solutions
LAB-D5-04
Build fluency in the KQL needed for the exam and for day-to-day troubleshooting by writing queries against Application Insights and Log Analytics tables (requests, dependencies, exceptions, traces, AppRequests, Perf, Heartbeat, InsightsMetrics, ContainerLogV2, ContainerLog, AzureActivity). Try each exercise yourself before reading the solution in the code block.
You need
- Data from LAB-D5-01 and LAB-D5-03, or the free Log Analytics demo environment (Azure portal > Monitor > Logs > demo)
- Basic familiarity with the Logs query editor
Steps
Show solution code
// E1
requests
| where timestamp > ago(1h) and success == false
| top 20 by timestamp desc
| project timestamp, name, resultCode, duration
// E2
requests
| where timestamp > ago(24h)
| summarize Requests = sum(itemCount) by name
| top 10 by Requests desc
// E3
requests
| where timestamp > ago(1d)
| summarize percentiles(duration, 50, 95, 99) by name
// E4
requests
| where timestamp > ago(6h)
| summarize count() by bin(timestamp, 5m), Outcome = tostring(success)
| render timechart
// E5
AppRequests
| where TimeGenerated > ago(1d)
| summarize Total = sum(ItemCount), Failed = sumif(ItemCount, Success == false)
by bin(TimeGenerated, 1h)
| extend FailurePct = round(100.0 * Failed / Total, 2)
// E6
dependencies
| where timestamp > ago(1d)
| summarize Calls = count(), AvgMs = avg(duration),
FailPct = 100.0 * countif(success == false) / count() by type, target
| top 5 by AvgMs desc
// E7
exceptions
| where timestamp > ago(2h)
| summarize Count = count() by type, outerMessage
| top 5 by Count desc
// E8
AppRequests
| where TimeGenerated > ago(1h) and Success == false
| join kind=inner (AppExceptions | project OperationId, ExceptionType) on OperationId
| project TimeGenerated, Name, ResultCode, ExceptionType
// E9
let op = "<paste operation_Id>";
union requests, dependencies, exceptions, traces
| where operation_Id == op
| project timestamp, itemType, cloud_RoleName, name, duration, success, message
| order by timestamp asc
// E10
Perf
| where TimeGenerated > ago(4h)
| where ObjectName == "Processor" and CounterName == "% Processor Time"
and InstanceName == "_Total"
| summarize AvgCPU = avg(CounterValue) by Computer, bin(TimeGenerated, 5m)
| render timechart
// E11
Heartbeat
| summarize LastSeen = max(TimeGenerated) by Computer
| where LastSeen < ago(15m)
// E12
InsightsMetrics
| where Namespace == "LogicalDisk" and Name == "FreeSpacePercentage"
| extend Disk = tostring(parse_json(Tags)["vm.azm.ms/mountId"])
| summarize arg_max(TimeGenerated, Val) by Computer, Disk
| where Val < 10
// E13
traces
| where severityLevel >= 3
| make-series Errors = count() default = 0 on timestamp from ago(1d) to now() step 1h
| render timechart
// E14
ContainerLogV2
| where TimeGenerated > ago(1h) and PodNamespace == "shop"
| where LogLevel == "error" or LogMessage has "error"
| project TimeGenerated, PodName, ContainerName, LogMessage
// E15
ContainerLog
| where TimeGenerated > ago(1h) and LogEntrySource == "stderr"
| summarize Lines = count() by ContainerID
| top 10 by Lines desc
// E16
ContainerLogV2
| where LogMessage has "status="
| parse LogMessage with * "status=" Status:int " latency_ms=" LatencyMs:long *
| summarize Requests = count(), P95 = percentile(LatencyMs, 95) by Status
// E17
AzureActivity
| where TimeGenerated > ago(7d)
| where OperationNameValue endswith "/DELETE" and ActivityStatusValue == "Success"
| project TimeGenerated, Caller, OperationNameValue, ResourceGroup, _ResourceId
// E18
requests
| where timestamp > ago(1d)
| extend Class = iff(duration < 500, "Fast", iff(duration < 2000, "OK", "Slow"))
| summarize Requests = sum(itemCount) by Class
| render piechartCheck your work
- Every query runs without syntax errors in the Logs editor for the matching table.
- E3 returns three percentile columns (percentile_duration_50/95/99) per operation.
- E13 returns exactly 24 or 25 points with zeros where no errors occurred.
- E8 returns only requests that have a matching exception (inner join).
- You can explain why take would be wrong in E1 and why sum(itemCount) is used in E2 and E18.
Go further
- Turn E5 into a log search alert that fires when FailurePct > 5 for the last 15 minutes.
- Rewrite E10 using InsightsMetrics (Processor/UtilizationPercentage) and compare the values.
- Build an Azure Monitor workbook with a time-range parameter that drives E3, E4 and E6.
- Use workspace('other-law').AppRequests in a union to compare two environments.