How to bulk change, enable, or disable the "auto-merge" settings for projects in Bitbucket Data Center
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The Bitbucket's "auto-merge" feature, introduced by Bitbucket 8.15, may not fit into your PR merging strategy - you may want to have it turned off.
You can do it manually within the Project and Repository settings from the "Auto-merge" settings option. You can even disable changing it on a repository level once it is set on a project-level.
However, after upgrading the Bitbucket it may happen that this option needs to be configured for many projects or repositories, and doing that manually is not convenient.
Environment
The solution has been validated in Bitbucket 8.19.10 but may be applicable to other versions.
Solution
There are two options to disable the "auto-merge" functionality:
1. Option to globally disable auto-merge for all projects
There is a bitbucket.properties
configuration file parameter feature.pull.request.auto.merge
to globally, for all projects and repositories, disable the "auto-merge" functionality.
By default, it is set to "true", so the PR auto-merge is enabled for all existing projects.
- You can explicitly set that parameter to "false" in the
bitbucket.properties
file and the pull-requests auto-merge functionality will disappear and won't be available for any project or repository.
Details are available on the page feature.pull.request.auto.merge. - If you decide to leave this parameter globally enabled, you will still be able to disable it on the project or repository level.
The page Auto-merge a pull request contains more information.
2. Setting auto-merge settings using REST API
There is also an option to use REST API to query and set "auto-merge" settings on a project level, and enable or disable the option to change the "auto-merge" settings in the repositories that are part of the project:
- Get pull request auto-merge settings.
- Create or update the pull request auto-merge settings.
- Delete pull request auto-merge settings.
Obs: In order to change auto-merge settings, you must either have project admin, admin or system admin permission.
For example:
To disable changing auto-merge settings, and at the same time set the auto-merge flag to "disabled"; the field "enabled" in the "data" section determines if auto-merge should be set to enabled or disabled:
curl \ -X PUT \ -H "Content-Type: application/json" \ --url "${URL}/rest/api/latest/projects/${PROJECT}/settings/auto-merge" \ --data '{ "enabled": false, "restrictionAction": "CREATE" }'
To allow changing of auto-merge settings, and at the same time enable auto-merge:
curl \ -X PUT \ -H "Content-Type: application/json" \ --url "${URL}/rest/api/latest/projects/${PROJECT}/settings/auto-merge" \ --data '{ "enabled": true, "restrictionAction": "DELETE" }'
Code snippets above are only examples, you need to provide an authorization header and proper Bitbucket URL and project code for them to work.