Pre-receive hook declined error during branch merging when using Bamboo Branch Updater option
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
This article describes how to resolve the pre-receive hook declined error when using the Branch Updater option in Bamboo Automatic branch merging settings.
Environment
The solution has been validated in Bamboo 9.2 with Bitbucket 8.1 linked to each other using Application links but may be applicable to other versions.
Diagnosis
When running the build that is using Branch Updater in Automatic branch merging settings, it's possible to see the following message in the build log file:
remote: *%%%%%.
remote: %%% %%%
remote: ,%# %%
remote: %% %%
remote: %# %%
remote: %% %
remote: %( %%
remote: %%%%%%%%%%%%%%%%%%%%%%%%%%%
remote: %#%*%#///////%# %%///////%%%%%%
remote: ,% %*%%******%# %%******%(%%,%
remote: %%/ %%/**%%/%%%%%%%(**#%( %%#
remote: %% %%% %(
remote: % .%
remote: *% %%%%% .%
remote: %# %%
remote: .%% .%%
remote: .%%.%%, %%%.%%/
remote: %%%%%%##%. #%%%%%. .%((%%%%%%
remote: %%#(((((((((%%, #%%(((((((((#%%.
remote: %%%((((((((((((((((((%%%, .%%%((((((((((((((((((#%%*
remote: %%(((((((((((((((((((((((((%(((((((((((((((((((((((((#%.
remote: ,%(((((((((((((((((((((((((((((((((((((((((((((((((((((((%#
remote: %#((((((((((((((((((((((((((((((((((((((((((((((((((((((((%
remote: %%%%%%%%%%%%%(((((((((((((((((((((((((((((((((%%%%%%%%%%%%%
remote: %% %####((((((###%%%%%%%%#(((((((((% ,%
remote: ,% %%%%%%#. %%%((((((%* %%
remote: #% %%%# %%
remote: .% .%%%%%%%%% %#
remote: % #%%% %
remote: % %%%% %*
remote: /%************/#%%%%%%######%%* ..,*/(%%
remote: %%######(((((((##################%%
remote: %%######(((((((((((((((((((((((((%%
remote: //////////////%%%%%%%%#########################%%///////// ///
remote: ----------------------------------------------------
remote: Branch refs/heads/feature/branch can only be modified through pull requests.
remote: Check your branch permissions configuration with the project administrator.
remote: ----------------------------------------------------
! [remote rejected] feature/branch -> feature/branch (pre-receive hook declined)
A detailed message can also be found in the <bamboo-home>/logs/atlassian-bamboo log
file:
Unable to push PROJ-PLAN-1 merge result: MergeResultSummaryImpl{integrationStrategy='BRANCH_UPDATER', mergeState='SUCCESS', pushState='FAILED', failureReason='Exception during push:
! [remote rejected] feature/merge_integration -> feature/merge_integration (pre-receive hook declined)
Cause
The error is caused by a restriction to the branch that is being updated from Bamboo to Bitbucket by Branch permissions configurations. This can be caused when the option Prevent all changes or Prevent changes without a pull request is enabled in Bitbucket Branch permissions settings for the target repository.
Solution
To resolve the pre-receive hook declined error, follow the steps below:
- In Bitbucket, access the target repository and go to Repository Settings > Access Keys;
Check the label (name) of the SSH key created by Bamboo. It should have the Bamboo URL (something like https://bamboo-server-url);
If you have multiples Access Keys with the same label, make sure to identify the correct one that Bamboo plan is using by going to Bamboo plan > Configure plan > Repositories tab or Bamboo configuration > Linked Repositories page, select the correct repository and then expand the Advanced options and check if the public key of the repository matches the one that is in the Access Keys in Bitbucket.
- Add the required SSH Access Key (name/label from the above step) into the Branch permissions and save the changes.