How I can ensure my pipeline only runs one build at a time?
Asked by AshTappin_BP:

If I push to a branch whilst a build is already running, then another build is triggered. This causes problems since my builds use the shared environment. How can I force the pipeline to only run one build at a time and any commits that are pushed, are queued for the next build?


Answers:
author: Theodora Boudale
body: Hi [@AshTappin_BP](/t5/user/viewprofilepage/user-id/2544651) ,

Are both builds deploying to the same environment defined in *Repository settings* \> *Deployments*?

If there is a build running that deploys to a certain deployment environment that you have defined in *Repository settings \> Deployments*, and a second build is triggered that deploys to the same environment, then the second build gets paused and you can resume it manually when the first one finishes.

Are you using deployment environments in your yml file? Could you share the yml file you are using, so we can better help you? You may remove the commands in the scripts and just add a description of what each step does if you don't feel comfortable sharing the exact yml file here; it would be useful to have an overview of the steps and understand where the problem arises.

Kind regards,  
Theodora

comments: author: AshTappin_BP
body: Thank you for your reply [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) I am using deployments but only for the deployment steps. Here is a summary of my yaml file:  

```
mage: atlassian/default-image:latest
pipelines:
  branches:
    master:
      - parallel:
          - step:
              name: "Provision CI"
              image: hashicorp/terraform:full
              <...>
              
          - step:
              name: "Build"
              image: maven:3.6.3-openjdk-14
              <...>
      - step:
          name: "Deploy to CI"
          deployment: test
          image: maven:3.6.3-openjdk-14
          <...>
      - step:
          name: Acceptance Test
          <...>
    
```

I tried adding *deployment: test* to every step but that wasn't allowed. I could collapse the steps into one big step. The main problem is when the *Acceptance Test* step is running another build could start and run the *Provision CI* step which alters the environment *Acceptance test* is using.  

A feature request that could circumvent this problem is mentioned here <https://community.atlassian.com/t5/Bitbucket-questions/Can-you-limit-the-number-of-concurrent-builds-in-pipelines/qaq-p/65932>


author: Theodora Boudale
body: Hi [@AshTappin_BP](/t5/user/viewprofilepage/user-id/2544651) ,

Thank you for explaining your use case, I understand the requirement.

There is indeed a feature request about this in our issue tracker:

* <https://jira.atlassian.com/browse/BCLOUD-16262>

I added a comment there quoting your previous reply, for our product managers to take into account. You can of course add any additional feedback, if you like. I would also suggest adding your vote (by selecting the **Vote for this issue** link). If you'd like to get notified via email on updates, you can add yourself as a watcher by selecting the **Start watching this issue** link. Any updates will be posted in that feature request.

For now, the only workaround I can think of is what you said as well, combine all steps into a big one ++and++ add the *deployment* keyword in the step. This way, any builds that are triggered when an existing one is running will be paused, and can be resumed manually from the Pipelines page.

If you have any questions, please feel free to let me know.

Kind regards,  
Theodora


author: AshTappin_BP
body: Thank you for your help [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

I have added my vote to the issue. We might have to do the workaround in the mean time.


Tags: bitbucket-pipelines

cloud