How to Test Across Versions With a Matrix in Azure Pipelines
A matrix leg per version sets a version variable that the setup task reads, so one job tests every supported version in parallel.
Define a matrix with one entry per version, each setting a variable like nodeVersion. Use that variable in a setup task (for example NodeTool@0) so each leg installs and tests against its own version.
Steps
- Add a
strategy.matrixentry per version, each setting a version variable. - Feed the variable into the setup task.
- Run the same install and test commands in every leg.
Pipeline
azure-pipelines.yml
jobs:
- job: test
pool:
vmImage: ubuntu-latest
strategy:
matrix:
node18:
nodeVersion: 18.x
node20:
nodeVersion: 20.x
node22:
nodeVersion: 22.x
steps:
- task: NodeTool@0
inputs:
versionSpec: $(nodeVersion)
- script: npm ci && npm testGotchas
- Every leg counts as a parallel job against your parallelism limit.
- Use
maxParallelto throttle legs when your agent capacity is limited. - Give each leg a distinct artifact name if it publishes output.
Related guides
How to Run Jobs in Parallel With a Matrix in Azure PipelinesFan one Azure Pipelines job out into parallel jobs with a matrix strategy, defining named legs that each set…
How to Publish Test Results and Code Coverage in Azure PipelinesSurface test outcomes and coverage in Azure Pipelines with PublishTestResults@2 and PublishCodeCoverageResult…