How to Run Jobs in Parallel With a Matrix in Azure Pipelines
A matrix strategy clones one job into several parallel legs, each with its own variable values.
Add strategy.matrix to a job with one entry per leg. Each entry is a name plus a map of variables, and Azure DevOps runs the legs in parallel up to maxParallel.
Steps
- Add
strategy.matrixto the job. - Give each leg a name and a map of variables.
- Reference a matrix variable as
$(name)inside the steps. - Cap concurrency with
maxParallelif needed.
Pipeline
azure-pipelines.yml
jobs:
- job: test
strategy:
maxParallel: 3
matrix:
linux:
imageName: ubuntu-latest
windows:
imageName: windows-latest
mac:
imageName: macos-latest
pool:
vmImage: $(imageName)
steps:
- script: npm ci && npm testGotchas
- Each leg counts as a parallel job and consumes a parallelism slot.
- Matrix variables are available as
$(name)in steps and in the pool selection. - For a self-healing managed pool, parallel matrix legs retry transient agent dropouts automatically.
Related guides
How to Test Across Versions With a Matrix in Azure PipelinesRun an Azure Pipelines test job against several language versions at once with a matrix that sets a version v…
How to Cache Dependencies in Azure PipelinesSpeed up Azure Pipelines by caching a package store with the Cache@2 task, keyed on a lockfile hash so unchan…