Using Pull Request Pipelines and Auto-Merging for Merge Train Alternatives in Bitbucket Cloud
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
This article explores how to achieve a merge train-like feature in Bitbucket by utilizing Pull Request Pipelines and the "Allow automatic merge when builds pass" merge check. These tools will help to ensure that code changes don't break the destination branch of the pull request and also enable the automatic merging of pull requests once all checks have passed and only the build completion is pending. This will help in implementing and optimizing your code review and integration processes.
Solution
To ensure that the code being introduced in a pull request does not break anything on the destination branch, it is crucial to test the changes beforehand. Bitbucket Pipelines offers a feature called pull-request triggered pipelines that can help with this task. These pipelines are triggered when a pull request is created or when the source branch of the pull request is updated, such as with a new commit.
The key difference with pull request pipelines is that during the build setup, the pipeline merges the destination branch into the source branch. This simulates the code changes that would occur during the actual merge, allowing you to test if the changes introduced by the pull request will cause any errors or issues in your build. This way, you can address those errors before actually merging the pull request.
Example of a pull request pipeline that will be triggered for any pull request that has a source branch starting with the word feature :
1
2
3
4
5
6
7
pipelines:
pull-requests:
feature/*:
- step:
name: Build for feature branch pull request
script:
- echo "Hello, feature branch PR!"
To further automate the process, you can combine pull request pipelines with the "Allow automatic merge when builds pass" merge check (Repository Settings > Branch restrictions > Merge Checks). This feature automatically merges the pull request if all other checks have passed and the build completion is the only remaining task. This eliminates the need for constant monitoring of the build status and manual merging once the build is complete. The branch restriction that contains the merge checks needs to be applied to the destination branch of the pull request.

Please note that "Allow automatic merge when builds pass" feature will allow you to select the Merge option in the Pull Request only if you don't have any non-build build merge checks preventing the merge. After clicking on the Merge option, Bitbucket will watch the build for you and merge it if the build passes or notify you in case it fails.
The below image illustrates the scenario where master branch (destination branch of the Pull Request) has "Allow automatic merge when builds pass" enabled in the branch restriction, and the Pull Request has only build-related merge-checks pending and the build is still running. Bitbucket will allow you to click on the Merge option to ao automatically merge the Pull Request if the running build passes :

By leveraging both pull request pipelines and automatic merging, you can implement a streamlined and efficient pull request review and integration process within Bitbucket. This combination of features not only saves time but also helps to keep your code-base stable and error-free, leading to a more smooth and productive development workflow.
If you are unable to achieve the desired result after following this article, please raise a support ticket or raise a community support ticket for further assistance.
Description | Using Pull Request Pipelines and Auto-Merging for Merge Train Alternatives in Bitbucket Cloud |
---|---|
Product | Bitbucket Cloud |
Was this helpful?