concurrency key in GitHub Actions. We’ll start with a simple Docker build-and-publish workflow, simulate a long-running deployment, and then introduce concurrency controls to ensure only one deployment runs at a time.
1. Base Workflow
This workflow builds, logs in, and publishes a Docker image when manually triggered:2. Adding a Long-Running Deploy Job
To demonstrate overlapping runs, let’s add adeploy job that runs the container and then sleeps for 10 minutes:
If you trigger this workflow while the previous deploy is still sleeping, you’ll end up with two simultaneous deployments—often a recipe for configuration drift or resource conflicts.

3. Understanding Concurrency in GitHub Actions
GitHub Actions offers aconcurrency key to group runs and control whether new runs cancel or queue behind in-progress ones:
Use a descriptive
group name (for example, production-deployment) so unrelated workflows do not interfere with each other.
4. Enabling Concurrency on the Deploy Job
Addconcurrency to the deploy job so that any new deployment run cancels the one in progress:
5. Demonstration: Cancel in Progress = true
- Trigger Workflow A →
deploystarts and sleeps. - Trigger Workflow B → cancels A’s
deployjob and starts B’s.

“The deploy job was canceled because a higher priority waiting request for the production deployment exists.”
6. Demonstration: Cancel in Progress = false
If you prefer to queue new runs behind in-progress ones, setcancel-in-progress: false:
- Trigger Workflow A → sleeps in
deploy. - Trigger Workflow B → its
dockerjob runs immediately, but itsdeployjob waits.

Conclusion
By definingconcurrency.group and choosing whether to cancel-in-progress, you can enforce single-instance deployments or queue them, protecting your production environment from conflicts and ensuring predictable rollouts.