How to Cancel In-Progress Runs in GitHub Actions
A concurrency group with cancel-in-progress kills older runs when a newer one starts.
Set concurrency.group to a key (often per branch) and cancel-in-progress: true. A new run cancels the prior run in the same group.
Steps
- Add a top-level
concurrency:block. - Key
groupon${{ github.workflow }}-${{ github.ref }}. - Set
cancel-in-progress: true.
Workflow
.github/workflows/ci.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: npm ci && npm run buildGotchas
- For deploys you often want
cancel-in-progress: falseto avoid interrupting a release. - Cancelling frees minutes; Latchkey runners are cheaper still and auto-retry transient failures.
Related guides
How to Set a Job Timeout in GitHub ActionsCap how long a GitHub Actions job can run with timeout-minutes so hung steps are killed instead of burning th…
How to Run Jobs in Parallel in GitHub ActionsRun independent GitHub Actions jobs in parallel by simply not declaring needs, so lint, test, and build all s…