This could be a bug in the bitbucket plugin
bitbucket plugin version: 1.0
Git plugin version: 2.2.1
Jenkins version: 1.532.2.3
See stackoverflow question:
If I configure a job to do a merge before the build then let SCM trigger the job it does not do a merge before the build. Since I have also turned on the git publisher the push fails because the target branch has diverged. The build is supposed to merge the source branch and the target branch together and push it back to target. If I kick off the build manually the the merge is done before the build and the git publisher runs without error.
Approximate steps to reproduce.
Create job named mergeAndBuild
Configure mergeAndBuild to use git
Configure mergeAndBuild to look for changes on sourceBranch and targetBranch
Add merge before build to git configuration
Name of repository: Origin
Branch to merge to: targetBranch
Merge strategy: default
Enable bitbucket build trigger.
Add git publisher to the build
Push Only If Build Succeeds: yes
Merge Results: yes
Make sure the bitbucket hook is configured with your jenkins server.
Then do something like the following
git clone giturl
git checkout -b sourceBranch
git add sourceBranch.txt
git commit -m "Add sourceBranch.txt"
git checkout master
git checkout -b targetBranch
git add targetBranch.txt
git commit -m "Add targetBranch.txT"
git push origin targetBranch:targetBranch
git push origin sourceBranch:sourceBranch
At this point it will build and the log will say:
commit notification 6161e4adb567c8be106ee8fa70594d67a756e481
Building remotely on 5a988271 in workspace /scratch/jenkins/workspace/da/b2.potter
Fetching changes from the remote Git repository
Fetching upstream changes from firstname.lastname@example.org:elosystemsteam/paypoint-potter.git
Checking out Revision 6161e4adb567c8be106ee8fa70594d67a756e481 (detached)
Then towards then end when the git publisher tries to push:
Pushing HEAD to branch B2-Bisque of origin repository
ERROR: Failed to push merge to origin repository
hudson.plugins.git.GitException: Command "git push email@example.com:elosystemsteam/paypoint-potter.git HEAD:B2-Bisque" returned status code 1:
stderr: To firstname.lastname@example.org:elosystemsteam/paypoint-potter.git
! [rejected] HEAD -> B2-Bisque (non-fast-forward)
error: failed to push some refs to 'email@example.com:elosystemsteam/paypoint-potter.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.