Run the same job across multiple Node versions.

Section: Reuse pipeline logic

GitHub Actions test matrix

yaml
yaml
strategy:
  matrix:
    node: [18, 20, 22]

steps:
  - uses: actions/setup-node@v4
    with:
      node-version: ${{ matrix.node }}
  - run: npm ci
  - run: npm test
Explanation

Matrices catch compatibility regressions early and avoid copy-pasting nearly identical jobs.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Reuse pipeline logic
GitLab matrix variables
Expand one logical job into multiple combinations.
OpenIn sheetyamlsame section
GitHub reusable workflow
Call a shared workflow from another repository or workflow file.
OpenIn sheetyamlsame section
Upload build artifacts
Publish files from one job for later download or deploy.
OpenIn sheetyaml1 tag match
Cache npm dependencies in GitHub Actions
Reuse package manager downloads between runs.
GitLab cache vs artifacts
Use cache for dependencies and artifacts for outputs.