CI/CD Pipelines: Reuse, Matrix, Cache, and Artifacts

Reusable workflows, matrix builds, caching strategies, and artifacts across common CI/CD systems.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Reuse pipeline logic

Keep pipelines DRY and scale tests across versions or platforms.

GitHub Actions test matrix

Run the same job across multiple Node versions.

yamlANYmatrixgithub-actions
yaml
strategy:
  matrix:
    node: [18, 20, 22]

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

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

GitLab matrix variables

Expand one logical job into multiple combinations.

yamlANYmatrixgitlab
yaml
test:
  stage: test
  parallel:
    matrix:
      - NODE_VERSION: ["18", "20", "22"]
  image: node:${NODE_VERSION}
  script:
    - npm ci
    - npm test
Notes

GitLab supports matrix-style expansion for parameterized jobs.

GitHub reusable workflow

Call a shared workflow from another repository or workflow file.

yamlANYreusableworkflow
yaml
jobs:
  ci:
    uses: org/shared-workflows/.github/workflows/node-ci.yml@main
    with:
      node-version: '20'
    secrets: inherit
Notes

Reusable workflows standardize CI across repositories and reduce duplicated YAML.

Speed and portability

Cache dependencies and move build outputs between jobs.

Cache npm dependencies in GitHub Actions

Reuse package manager downloads between runs.

yamlANYcachenpm
yaml
- uses: actions/setup-node@v4
  with:
    node-version: 20
    cache: npm
Notes

Prefer built-in setup action caching when available because it is simpler and less error-prone.

Upload build artifacts

Publish files from one job for later download or deploy.

yamlANYartifactgithub-actions
yaml
- uses: actions/upload-artifact@v4
  with:
    name: web-dist
    path: dist/
Notes

Artifacts decouple build jobs from deployment jobs and provide downloadable outputs for debugging.

GitLab cache vs artifacts

Use cache for dependencies and artifacts for outputs.

yamlANYcacheartifactsgitlab
yaml
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm/

artifacts:
  paths:
    - dist/
  expire_in: 1 week
Notes

Cache is for speeding up repeated work; artifacts are for preserving job outputs.

Recommended next

No recommendations yet.