How to Limit a Single Job With Concurrency in GitHub Actions
Placing the concurrency block under a job scopes serialization to that job alone, not the entire workflow.
Concurrency can sit at the workflow level or under an individual job. Putting it on the deploy job lets build and test keep running in parallel while only deploys are serialized.
Steps
- Leave the workflow-level
concurrencyout (or keyed loosely). - Add a
concurrency:block inside the specific job. - Use a stable group for that job so its runs queue.
Workflow
.github/workflows/ci.yml
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: npm test
deploy:
needs: test
runs-on: ubuntu-latest
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: false
steps:
- run: ./deploy.shGotchas
- Job-level and workflow-level concurrency are independent; you can use both, but they must not deadlock each other.
- A queued job counts against the run duration, so a long queue can hit the workflow timeout.
Related guides
How to Group Concurrency by Workflow and Ref in GitHub ActionsBuild a robust GitHub Actions concurrency key from github.workflow and github.ref so each workflow deduplicat…
How to Use a Static Concurrency Group for a Singleton Job in GitHub ActionsGuarantee only one instance of a job runs at a time across the whole repo in GitHub Actions by giving it a co…