How to Scope a Concurrency Group per Environment in GitHub Actions
Keying the concurrency group on the environment name keeps each target deploy lane independent.
Set concurrency.group to a key that includes the environment name. Deploys to different environments run in separate lanes, while deploys to the same one share a lane.
Steps
- Add a job-level
concurrency:block. - Include the environment name in
group. - Pick
cancel-in-progressper your release policy.
Workflow
.github/workflows/ci.yml
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.target }}
concurrency:
group: deploy-${{ inputs.target }}
cancel-in-progress: false
steps:
- run: ./deploy.sh --env ${{ inputs.target }}Gotchas
- Omitting the environment from the group serializes all deploys into one lane.
- For deploys prefer
cancel-in-progress: falseso a running release is not interrupted.
Related guides
How to Prevent Concurrent Deploys to the Same Environment in GitHub ActionsSerialize GitHub Actions deploys to one environment with a concurrency group and cancel-in-progress false, so…
How to Cancel In-Progress Runs in GitHub ActionsCancel superseded GitHub Actions runs automatically with a concurrency group and cancel-in-progress, so only…