How to Limit Concurrent Matrix Jobs With max-parallel in GitHub Actions
max-parallel caps how many matrix legs run simultaneously, queuing the rest instead of launching them all at once.
Set strategy.max-parallel to the number of legs you want running concurrently. GitHub starts that many and releases the next as each finishes.
Steps
- Add
max-parallel:understrategy. - Pick a number below your total legs to throttle them.
- Use it when legs share a rate-limited external resource.
Workflow
.github/workflows/ci.yml
jobs:
test:
strategy:
max-parallel: 2
matrix:
shard: [1, 2, 3, 4, 5, 6]
runs-on: ubuntu-latest
steps:
- run: npm ci && npm test -- --shard=${{ matrix.shard }}/6Gotchas
- max-parallel throttles concurrency but does not reduce the total job count or minutes.
- It is a per-matrix limit; concurrency across workflows needs a
concurrency:group.
Related guides
How to Control fail-fast in a GitHub Actions MatrixChoose whether a GitHub Actions matrix stops at the first failing leg or runs every combination to completion…
How to Cache Dependencies Per Matrix Leg in GitHub ActionsGive each GitHub Actions matrix leg its own cache by including a matrix value in the actions/cache key, so a…