Limit Bitbucket Pipelines to a single concurrent build per branch
Platform Notice: Cloud Only - This article only applies to Atlassian apps on the cloud platform.
Summary
This article explains how to configure Bitbucket Pipelines so that only one build runs at a time for each branch, preventing multiple concurrent builds on the same branch.
Understanding the problem
By default, Bitbucket Pipelines allows multiple builds to run concurrently, even on the same branch. Some workflows may require that only one build per branch runs at a time (for example, when using tools or environments that can't handle parallel builds on the same branch).
Solution
Using concurrency groups
Bitbucket Pipelines provides the concurrency-group option, which can be used to limit the number of concurrent builds. To achieve single concurrency per branch, you can use the default variable branch name $BITBUCKET_BRANCH as part of the concurrency group name.
Example bitbucket-pipelines.yml
pipelines:
default:
- step:
name: "Build"
script:
- echo "Building the application"
concurrency:
group: "build-${BITBUCKET_BRANCH}"How it works:
The
groupvalue uses the branch name variable${BITBUCKET_BRANCH}to create a unique concurrency group for each branch.This ensures that only one build per branch can run at a time.
Was this helpful?