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
GitHub Actions test matrix
strategy:
  matrix:
    node: [18, 20, 22]

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

# Run the same job across multiple Node versions.

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

# Expand one logical job into multiple combinations.

GitHub reusable workflow
jobs:
  ci:
    uses: org/shared-workflows/.github/workflows/node-ci.yml@main
    with:
      node-version: '20'
    secrets: inherit

# Call a shared workflow from another repository or workflow file.

## Speed and portability
Cache npm dependencies in GitHub Actions
- uses: actions/setup-node@v4
  with:
    node-version: 20
    cache: npm

# Reuse package manager downloads between runs.

Upload build artifacts
- uses: actions/upload-artifact@v4
  with:
    name: web-dist
    path: dist/

# Publish files from one job for later download or deploy.

GitLab cache vs artifacts
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm/

artifacts:
  paths:
    - dist/
  expire_in: 1 week

# Use cache for dependencies and artifacts for outputs.

Recommended next

No recommendations yet.