Azure DevOps Part 5: Multi-Stage Pipelines, Security, and Troubleshooting
· Azure DevOps, YAML Pipelines, DevOps Security, Troubleshooting, DevOps, azure-devops-series
Part 4 gave you a build pipeline, artifacts, and a release pipeline with approvals and rollback. Part 5 pulls those pieces into one multi-stage YAML pipeline, shows how templates keep it maintainable, covers the security model (RBAC, personal access tokens, audit logs), and ends with a repeatable method for troubleshooting when something breaks. The video above runs about 2:20. This article follows its order and adds the design guidance a solutions architect would give before this goes into production.

Multi-stage YAML: build the artifact once, then promote it through Dev, QA, UAT, and Production.
Azure DevOps series
All six parts of the series, in order:
- Part 1: Core Services & Architecture
- Part 2: Repos, Branching & YAML Pipelines
- Part 3: Agents, Variables, Secrets & Service Connections
- Part 4: CI/CD, Build, Artifacts & Release
- Part 5: Multi-Stage Pipelines, Security & Troubleshooting (you are here)
- Part 6: End-to-End Workflow, Best Practices & Interview Prep
Previous: Part 4: CI/CD, Build, Artifacts & Release · Next: Part 6: End-to-End Workflow, Best Practices & Interview Prep
Multi-stage YAML: CI and CD in one file
In the earlier parts, CI and CD could be separate things: a build pipeline here, a classic release pipeline there. A multi-stage YAML pipeline puts the whole journey in one azure-pipelines.yml: build the artifact once, then deploy to Dev, QA, UAT, and Production. Pull requests change the pipeline like application code, so delivery gets review and history.
The skeleton has four ideas: stages (big phases such as Build, Dev, QA), jobs (units that run on an agent), steps (the tasks and scripts), and environments (named deployment targets that carry history, approvals, and checks).

Stage control: dependsOn, condition, a deployment job, and an environment, where approvals and checks attach.
The video's stage snippet shows the control mechanics:
- stage: QA
dependsOn: Dev
condition: succeeded()
jobs:
- deployment: DeployQA
environment: 'qa'
# approvals + checks are configured on the environment
Here is a fuller version you can adapt:
trigger:
branches:
include: [ main ]
stages:
- stage: Build
jobs:
- job: BuildApp
pool:
vmImage: ubuntu-latest
steps:
- script: dotnet publish src/Web -c Release -o $(Build.ArtifactStagingDirectory)/web
- publish: $(Build.ArtifactStagingDirectory)/web
artifact: web
- stage: Dev
dependsOn: Build
jobs:
- deployment: DeployDev
environment: dev
pool: { vmImage: ubuntu-latest }
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying $(Pipeline.Workspace)/web with config for dev"
- stage: QA
dependsOn: Dev
condition: succeeded()
jobs:
- deployment: DeployQA
environment: qa
pool: { vmImage: ubuntu-latest }
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying to qa"
- stage: Production
dependsOn: QA
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- deployment: DeployProd
environment: production # approval + branch control checks live here
pool: { vmImage: ubuntu-latest }
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying to production"
A few points an architect watches for:
- By default, stages run sequentially in the order written.
dependsOnmakes the order explicit and lets you fan out (Dev and a security scan in parallel) or fan in. conditiondecides whether a stage runs once its dependencies finish.succeeded()is the default. Useand(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))to confine production tomain, andalways()orfailed()for cleanup and notification stages.- A deployment job downloads the pipeline artifact for you in its
deployhook. You do not need a separate download step unless you opt out. - Approvals and checks are not in the YAML. They are configured on the environment by its owner, so people editing the pipeline file cannot remove them. The comment in the video's snippet says exactly that.
Same artifact, different configuration
The video's one-line summary is worth memorizing: build once, test many, deploy safely. The artifact that reaches Production is byte-for-byte the one that passed QA and UAT. What changes per environment is configuration: connection strings, URLs, feature flags, scale settings.
Keep configuration out of the artifact. Use variable groups scoped per stage, environment-specific pipeline variables, or an app configuration service, and pull secrets from Azure Key Vault. If you find yourself running a different build for each environment, you have lost traceability, and a Production bug may not reproduce in QA.
YAML templates: stop copy-pasting pipelines

YAML templates: reusable steps, jobs, and stages, with parameters such as environment: 'qa'.
The first multi-stage pipeline you write is usually 80 lines. The tenth team's copy of it is 400 lines and slightly different everywhere. Templates solve that. The video names three levels of reuse, steps, jobs, and stages, and shows parameters like environment: 'qa'.
A step template, templates/deploy-steps.yml:
parameters:
- name: environment
type: string
- name: appName
type: string
steps:
- script: echo "Deploying ${{ parameters.appName }} to ${{ parameters.environment }}"
And a consumer:
steps:
- template: templates/deploy-steps.yml
parameters:
environment: 'qa'
appName: 'contoso-web'
Templates come in two flavors that you should not confuse. Include templates (- template: inside steps, jobs, or stages) drop reusable blocks into your pipeline. Extends templates (extends: template:) go the other way: the pipeline file hands control to a parent template, which defines the required structure and lets the author fill in parameters, for example extends: template: templates/build.yml with parameters: environment: 'qa'.
The extends pattern is the governance tool. A platform team publishes secure-pipeline.yml that always runs a credential scan, dependency scan, and signing step, and exposes a small set of parameters. Teams extend it. Combined with the Required template check on a service connection or environment, a pipeline that does not extend the approved template simply will not deploy.
Template hygiene for enterprises:
- Version your templates. Keep them in a dedicated repository and reference a tag or branch with
resources: repositories:. Avoid pointing every team atmainof the template repo with no release process. - Use typed parameters (
string,boolean,object, withvalues:where a closed list makes sense) so mistakes fail at compile time. - Template expressions
${{ }}evaluate at compile time, while$[ ]and$( )evaluate later. Mixing them up is a common template bug.
Security: RBAC, tokens, and audit logs
A pipeline can read source code, hold secrets, and deploy to production. That makes it a high-value target, so the security model is part of the architecture, not an afterthought.

RBAC: Project Collection Administrator, Project Administrator, Build Administrator, Contributor, and Reader.
RBAC and least privilege
Azure DevOps uses role-based access control built on security groups. The video lists the built-in ones, from most to least powerful: Project Collection Administrators (organization-wide), Project Administrators, Build Administrators, Contributors, and Readers. Most developers belong in Contributors. Very few people should be in the administrator groups.
Rules that hold up in audits:
- Assign permissions to groups, not individuals. When someone changes teams, you change one group membership instead of hunting through dozens of ACLs. Sync those groups from Microsoft Entra ID so joiners and leavers follow HR processes.
- Least privilege. Grant the narrowest role that lets the person do the job. Remember that Build Administrators can edit pipelines and manage their security, so treat it as a sensitive role.
- Protect the resources, not just the pipelines. Environments, service connections, agent pools, variable groups, and secure files each have their own security roles and can carry checks. Production secrets should sit in a variable group or Key Vault that only the Production stage can use.
- Separate duties. The people who write the code should not be the only people who can approve the Production deployment.
- Limit job authorization scope for pipelines to the current project, and restrict who can create service connections.
Personal access tokens (PATs)
The video's guidance is short: use only the scopes needed, set a short expiration, and regenerate the token if it leaks. Microsoft's current documentation goes further and tells you to avoid PATs whenever a more secure method exists. For applications and automation, prefer Microsoft Entra tokens, managed identities, or service principals, and for pipelines, use a service connection. If a tool truly requires a PAT, create an organization-scoped one with the minimum scopes and the shortest practical lifetime. Administrators can restrict full-scoped PATs, set a maximum lifetime, and control automatic revocation of leaked tokens.
Two operational notes: a PAT is tied to the person who created it, so it stops working or changes behavior when that person's access changes, and Azure DevOps is retiring global PATs, which stop working on January 27, 2027. Inventory your tokens now and move to organization-scoped PATs or Entra authentication.
Audit logs
The video recommends logging permission changes, pipeline runs, approvals, and token activity and streaming them to Azure Monitor and Log Analytics. Here is how that maps onto the current product:
- Auditing is off by default and available only for organizations backed by Microsoft Entra ID. A Project Collection Administrator turns it on under Organization settings, Policies, Log Audit Events.
- Audit events include permission changes, deleted resources, branch policy changes, and log access. Events are kept for 90 days, so export them or use audit streaming for longer retention.
- Streaming sends events to a SIEM such as Azure Monitor Log Analytics, Splunk, or Event Grid, where you can build alerts, for example "a full-scope PAT was created" or "a branch policy was removed."
- Sign-in events are not tracked in the Azure DevOps audit log. Review sign-ins in Microsoft Entra ID. Likewise, membership changes inside Entra groups appear in Entra audit logs, not here.
- Pipeline run history and approval records live with the pipeline runs and environments, so keep retention long enough to answer an auditor.

Audit logs: who changed what, and when. Stream them to your SIEM.
Troubleshooting: what to do when it breaks
Every pipeline fails eventually. The skill is reading the failure quickly. The video uses a simple run view: Initialize passed, Checkout passed, Build passed, Test failed with ##[error] 3 tests failed, and Publish did not run.

When it breaks: find the first red step, read its log, and ignore everything after it.
How to read it:
- Find the first failed step. Later steps are skipped or are consequences.
- Open that step's log and search for
##[error]. The line right above it is usually the real cause. - Turn on verbose logs. For one run, choose Run pipeline and select Enable system diagnostics. For all runs, add a variable named
system.debugwith the valuetrue. Remember to turn it off afterward, because debug logs can expose more than you want. - Check the agent when the job fails before any task starts. If Initialize itself fails or the job never begins, the problem is the machine, not your code. On self-hosted agents, look at the
_diagfolder, which holds the agent and worker diagnostic logs showing how the agent was configured and what happened as each job ran. - Reproduce locally when you can. Run the same
dotnet testornpm testcommand on your machine to separate environment issues from code issues.
The five common failures

Common failures and their usual causes.
| Failure | Usual cause | First move |
|---|---|---|
| Build failed | Code error or the wrong SDK or tool version | Read the compiler error. Pin versions with UseDotNet@2 or NodeTool@0. |
| Tests failed | A real bug, flaky test, or bad test data | Open the Tests tab, check whether it fails on rerun, fix data setup. |
| Artifact not found | Wrong path or name, or missing permissions | Confirm the artifact name and publish path. Check that the run still exists, since deleting a run deletes its artifacts. |
| Deploy failed | A broken service connection | Check expiry of the service principal secret and its role on the target resource. Prefer workload identity federation to avoid expiring secrets. |
| Stuck in queue | No matching agent | Look for offline agents, unmet demands, or no free parallel jobs. |
A deploy that worked yesterday and fails today is very often an expired secret or rotated credential. A failure that appears only in Production is usually a configuration or permission difference between environments, another reason to keep config out of the artifact.
The method

The video ends on the same four verbs every time: find the root cause, fix it, rerun, and validate. Do not skip the last one. A rerun that goes green after a flaky retry has not fixed anything, and "it passed the second time" is a bug report for next week.
Interview questions from this part
How do you pass an artifact between stages in YAML? Publish it in the build stage with publish. Deployment jobs download it automatically in their deploy hook, and regular jobs use download: current.
Where do approvals live in a YAML pipeline? On the environment (or other protected resource) as checks, not in the YAML, so pipeline authors cannot remove them.
Include template or extends template? Include templates insert reusable steps, jobs, or stages. Extends templates enforce a required structure, and can be mandated with the Required template check.
How do you secure access? Groups, least privilege, protected resources, Entra-based identities over PATs, and audit streaming.
What comes next
You can now build a multi-stage pipeline, reuse it through templates, lock it down, and debug it when it fails. In Part 6: End-to-end workflow, best practices, and interview questions, the series finale, we follow one change from a developer's laptop all the way to production and finish with the questions you should be ready to answer.
If you want more short, practical lessons like this on AI, code, cloud, and security, follow @rankcore.ai on Instagram.
Want to go deeper?
Our step-by-step video courses turn these ideas into results.
Comments
No comments yet — be the first.