Skip to content
Latchkey

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.matrix entry 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 test

Gotchas

  • Every leg counts as a parallel job against your parallelism limit.
  • Use maxParallel to throttle legs when your agent capacity is limited.
  • Give each leg a distinct artifact name if it publishes output.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →