Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Single Concurrent Build per Branch

Curtis
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2025

We are migrating an application from Bamboo to Bitbucket Pipelines. This application is unique in that it should only have one build running per branch at a time. This wasn't a problem in Bamboo, as that was the default. But in Bitbucket Pipelines, you push a 2nd commit for the same branch, it will execute another pipeline and build for the same branch.

I know Pipelines allows only one execution going per Deployment environment, but I've not seen any configuration to do this for non-deployments and per branch.

I could limit it to 1 by having a single self-hosted runner, but then only one build would happen at a time for any branch. Two different branches can build concurrently, we just can't have the same branch have a 2nd build triggered.

What is our best option to move forward with using Bitbucket Pipelines to replace Bamboo in this regard?

Thanks.

2 answers

1 accepted

0 votes
Answer accepted
Curtis
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2025

This can be accomplished using the concurrency groups control with value as the branch name, thanks to Pipelines working with variables now in more places outside of the scripts section.

- step:
name: Build Step
concurrency-group: build-${{BITBUCKET_BRANCH}}
script:
# Only blocked if it is the same branch
- echo "Performing build steps..."

 I had initially tried this, but it didn't work because I missed the curly braces around the variable, which is required when using variables outside of the script section.

0 votes
Aron Gombas _Midori_
Community Champion
October 25, 2025

I don't think that you can implement a "one build per branch" model out of the box using the built-in features.

Maybe, you could invent your own concurrency control:

  1.  you maintain a short-living flag "isBuildRunning" per branch somewhere 
  2. every build check this flag and only proceeds if it is FALSE
  3. if it proceeds, it sets it to TRUE
  4. when it completes, it sets to FALSE

 

Curtis
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2025

That is a good idea for creating your own specific concurrency control. You could maybe use the Bitbucket variables through the API to store that "flag". That used potentially with the check for running Pipelines as well should cover any unique concurrency requirements.

This example is simple and just checking if any Pipeline is running against the current branch. The query can be altered to your specific needs.

- step:
name: Build Step
script:
# Check if another Pipeline is running against same branch
- export RESPONSE=$(curl --request GET --url $PIPELINES_URL --header "Content-Type:application/json" --header "Authorization:Bearer $BITBUCKET_API_TOKEN" -G -d "target.branch=$BITBUCKET_BRANCH" -d "status=BUILDING")
- export SIZE=$(echo $RESPONSE | jq -r '.size')
- if [[ $SIZE -gt 1 ]]; then echo "Found another running build for this branch. Stopping build."; exit 1; fi

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events