matrix

strategy:

Fans a job out across a matrix of variable combinations. Each combination becomes an independent job whose values are exposed via the `matrix` context.

strategy:
  matrix:
    <key>: [v1, v2]
    include: [...]
    exclude: [...]
  fail-fast: true|false
  max-parallel: <n>

Common values / subkeys

Value / Subkey Purpose
matrix.<key> List of values to enumerate; multiple keys are combined cartesian-product
matrix.include Add extra combinations or attach extra fields to matching combos
matrix.exclude Remove specific combinations
fail-fast Cancel remaining legs when one fails (default true)
max-parallel Limit concurrent legs
${{ matrix.<key> }} Read the current leg's value inside the job

Examples

strategy:
  matrix:
    node: [18, 20, 22]
    os: [ubuntu-latest, windows-latest]

Cartesian product: 6 jobs

strategy:
  matrix:
    node: [18, 20]
    include:
      - node: 22
        experimental: true

`include` adds a new leg; matching existing combos merges extra fields

strategy:
  fail-fast: false
  matrix:
    os: [ubuntu-latest, windows-latest, macos-latest]

Keep other legs running when one fails

strategy:
  matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}

Dynamic matrix built from an upstream job output

Gotcha

`include` adds a NEW combination unless every key it names already exists in a generated combo — then it merges into that combo; `exclude` is applied after `include`. Matrix is capped at 256 jobs per workflow run.

Related keywords

← All GitHub Actions syntax · Git commands · Cron syntax