Pipelines: maintain pipelines · Topic 1 of 2
Pipeline Health and Optimization
AZ-400 pipeline health: failure rate, duration and flaky test reports, then optimizing cost, time and reliability with caching, parallelism and cancellation.
- 5 min
- Monitor failure rate, duration, queue time and flaky tests. Use percentiles for duration.
- Azure DevOps has pipeline analytics and test analytics. GitHub has Actions usage and performance metrics.
- Caching uses
Cache@2oractions/cachewith a key built from a lock file hash.
What it is
Pipeline health is how reliably and quickly your pipelines do their job. A healthy pipeline passes when the code is good, fails when it is bad, finishes fast and costs little. Optimization is the work of moving a pipeline toward that: less waiting, fewer false failures, lower bills.
Both start with measurement. Without numbers, people optimize what they can see rather than what matters.
How it works
What to monitor
| Signal | Why it matters |
|---|---|
| Failure rate (pass rate) | A rising failure rate means broken code, an unstable environment or flaky tests |
| Duration | Long runs slow feedback. Look at percentiles (typical and worst case), not only averages |
| Queue time | Time spent waiting for an agent shows a shortage of parallel jobs or agents |
| Failing tasks and steps | Shows which step fails most, such as a restore step or a particular test |
| Flaky tests | Tests that pass and fail on the same code erode trust |
| Cost | Minutes used, agent hours, parallel jobs |
Where to see it
| Platform | Tools |
|---|---|
| Azure DevOps | Pipeline analytics and reports for pass rate, run duration and failure reasons, test analytics, dashboard widgets such as build history and pass rate, and notification subscriptions for failed runs |
| GitHub | The Actions tab with run history, Actions usage and performance metrics for organizations, and workflow notifications |
| Azure Monitor / Log Analytics | Send pipeline events through service hooks or webhooks to a workspace to build alerts and dashboards across tools |
Set alerts on the trends that matter: a spike in failures on main, or a run that takes twice its normal time.
Flaky tests
A flaky test gives different results with no code change, because of timing, shared state, test order or an unreliable dependency.
- Detect: Azure Pipelines test analytics can identify flaky tests, and it can rerun failed tests (the VSTest task supports rerunning failures) to separate real failures from noise.
- Contain: mark known flaky tests so they do not block the build, but keep them visible.
- Fix: remove shared state, replace sleeps with waits for conditions, and isolate external calls. Track a flaky test as a bug with an owner.
Optimizing time
| Technique | How |
|---|---|
| Caching | Cache package restores and build outputs with the Cache@2 task (a key and optional restore keys) or actions/cache in GitHub. The key usually includes a hash of the lock file |
| Parallelism | Run independent jobs at the same time, slice test suites with strategy: parallel, and use a matrix where it saves wall clock time |
| Shallow fetch | fetchDepth: 1 avoids downloading all history |
| Smaller work | Path filters, incremental builds, running only affected tests |
| Order for fast failure | Run quick checks, such as lint and unit tests, first |
| Faster compute | Larger or self-hosted agents with warm caches for the slowest stages |
| Pipeline artifacts | PublishPipelineArtifact and DownloadPipelineArtifact move files faster than the older build artifacts |
- task: Cache@2
inputs:
key: 'npm | "$(Agent.OS)" | package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(Pipeline.Workspace)/.npm
Optimizing cost
- Cancel redundant runs. In Azure Pipelines, pull request validation runs are cancelled when a newer commit arrives. In GitHub use
concurrencywithcancel-in-progress: true. - Avoid needless runs with path filters,
[skip ci]and batching. - Right size the agents. Do not use a large machine for a lint job.
- Scale self-hosted capacity to zero when idle and use cheaper capacity for non urgent work.
- Clean up artifacts and old runs so storage does not keep growing (see retention).
Optimizing concurrency
The number of jobs that can run at once is limited by licensed parallel jobs in Azure Pipelines, by plan limits in GitHub, and by your own agent count. If queue time is high, add capacity or reduce wasted runs. If queue time is near zero, more parallelism only adds cost. Use maxParallel on matrices and exclusive locks where concurrent deployments to one target would conflict.
Optimizing reliability
- Pin tool and action versions so an upstream release does not break the build.
- Get dependencies from your own feed with an upstream source rather than directly from public registries.
- Use
retryCountOnTaskFailurefor steps that depend on the network, andtimeoutInMinutesso a hung job cannot hold an agent. - Keep scripts idempotent and use ephemeral agents so a job cannot be broken by leftovers from earlier runs.
- Keep agent software and images patched.
A worked scenario
A team's main pipeline takes 40 minutes and fails once in five runs. Analytics show 15 minutes in package restore and that three tests produce most failures. They add caching keyed on the lock file, fetch with fetchDepth: 1, split the test suite across four parallel jobs and quarantine the three flaky tests with tickets. They also cancel superseded pull request runs. Duration falls to 14 minutes and the failure rate drops.
What to remember for the exam
- Monitor failure rate, duration, queue time and flaky tests. Use percentiles for duration.
- Azure DevOps has pipeline analytics and test analytics. GitHub has Actions usage and performance metrics.
- Caching uses
Cache@2oractions/cachewith a key built from a lock file hash. - Cancel superseded runs: automatic for pull request builds in Azure Pipelines,
cancel-in-progressin GitHub. - High queue time means more parallel capacity could help. Low queue time means it would not.
A question about "reducing restore time" is caching. "Stop wasting minutes on old commits" is run cancellation.
How the exam asks about this
- "Identify tests that sometimes pass and sometimes fail." Flaky test detection in test analytics.
- "Cut package restore time in every run." Cache the package folder.
- "Pipelines wait a long time before starting." Check queue time and parallel job or agent capacity.
- "Shorten test time without removing tests." Run them in parallel jobs.
Common mistakes
Optimizing by guessing. Measure first.
Caching without a good key. A key that never changes serves stale data. One that always changes never hits.
Hiding flaky tests. They need an owner and a fix.
Adding parallel jobs when the real problem is a slow step. Parallelism does not shorten one long task.
Check yourself
Which metric shows time spent waiting for an agent?
Queue time.
Which Azure Pipelines task caches folders such as package restores?
Cache@2.
How do you cancel an older GitHub Actions run when a newer one starts for the same branch?
Use concurrency with cancel-in-progress set to true.
Topic 1 of 2 in Pipelines: maintain pipelines
Test yourself on Pipelines: maintain pipelines
The full Microsoft AZ-400 question bank has 766 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.