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 testExplanation
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.
GitHub reusable workflow
Call a shared workflow from another repository or workflow file.
Upload build artifacts
Publish files from one job for later download or deploy.
Cache npm dependencies in GitHub Actions
Reuse package manager downloads between runs.