# Avoid concurrent workflows on main branch

**URL:** <https://discuss.circleci.com/t/avoid-concurrent-workflows-on-main-branch/46148>\
**Category:** Deployments\
**Tags:** deployment\
**Created:** [November 17, 2022, 3:06pm UTC](https://discuss.circleci.com/t/avoid-concurrent-workflows-on-main-branch/46148 "2022-11-17T15:06:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtandrup](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mtandrup/32/31631_2.png) [@mtandrup](https://discuss.circleci.com/u/mtandrup)\
**Post date:** [November 17, 2022, 3:06pm UTC](https://discuss.circleci.com/t/avoid-concurrent-workflows-on-main-branch/46148/1 "2022-11-17T15:06:00Z")

</div>

Hi

We have a build and release workflow running on our main branch. It checks out the code builds it, deploys it to our staging environment and then runs tests against the staging environment.  
Since we only have one staging env we cannot have a later workflow start before we are done with deploy and testing.

I’ve seen a orbs like eddiewebb/queue that allows to pause a workflow until the previous workflow is done.  
But if multiple people merges to our main branch while deploy+test is running the last person to merge will have to wait a long time for his change to hit staging.

So is there a way to cancel a paused workflow if there are new workflows starting, but not cancel the workflow currently deploying and testing?  
 ![workflows](https://global.discourse-cdn.com/circleci/original/3X/4/6/4674ab14bd9d4515fed1b0825ab05843e9144fc2.png)

Best regards,  
Mads

---

<div class="post-metadata">

**Author:** ![yannCI](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/yannci/32/24866_2.png) [@yannCI](https://discuss.circleci.com/u/yannCI)\
**Post date:** [November 26, 2022, 9:57pm UTC](https://discuss.circleci.com/t/avoid-concurrent-workflows-on-main-branch/46148/2 "2022-11-26T21:57:43Z")

</div>

Hi @mtandrup,

You mention “paused workflows”. Does this mean you’re using [approval jobs](https://circleci.com/docs/configuration-reference/#type)?

If so, you could use the same logic as that used in [this workaround](https://discuss.circleci.com/t/workaround-auto-cancel-redundant-builds-on-the-default-branch/39468), but only match workflows in an `on_hold` state.

Let me know if this helps.

---

<div class="post-metadata">

**Author:** ![mtandrup](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mtandrup/32/31631_2.png) [@mtandrup](https://discuss.circleci.com/u/mtandrup)\
**Post date:** [December 5, 2022, 8:28am UTC](https://discuss.circleci.com/t/avoid-concurrent-workflows-on-main-branch/46148/3 "2022-12-05T08:28:46Z")

</div>

Hi @yannCI

We do use `hold:` approval step. But when I mentioned pausing I was referring to something like what [GitHub - eddiewebb/circleci-queue: CircleCI orb to block/queue jobs to enforce max concurrency limits](https://github.com/eddiewebb/circleci-queue) does.

In your example you end up cancelling the older running build, right?

What I would like to accomplish is:

1. Dev merges PR to master
2. Trigger pipeline to build, test and deploy to our environments.
3. While the build from step 2 is building, any dev merges PR to master should not start a new build.
4. Immediately after the build from step 2 is done, start a new build to pick up all the commits happening in step 3.

And continue that process until there are no more commits coming in.
