How to Use a Matrix Strategy in Azure Pipelines
A matrix expands one job into several named legs, each with its own variable values, running in parallel.
Under a job, set strategy.matrix to a map of named configurations. Each leg becomes a parallel job and exposes its matrix variables to steps.
Matrix across Node versions
Each leg sets nodeVersion; maxParallel caps concurrent legs.
azure-pipelines.yml
jobs:
- job: Test
strategy:
maxParallel: 2
matrix:
node18:
nodeVersion: '18.x'
node20:
nodeVersion: '20.x'
steps:
- task: NodeTool@0
inputs:
versionSpec: $(nodeVersion)
- script: npm ci && npm testGotchas
- Matrix leg names become part of the job identity - keep them stable to preserve history.
- Each leg runs on its own agent, so each must reinstall dependencies (cache them to save time).
maxParallellimits agent consumption when your parallel-job quota is small.
Related guides
How to Run Parallel Jobs in Azure PipelinesRun jobs concurrently in Azure Pipelines by declaring independent jobs without dependsOn, plus parallel slici…
How to Reuse Pipeline Templates in Azure PipelinesAvoid copy-paste in Azure Pipelines with step, job, and stage templates - pass parameters, set defaults, and…