Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-22724

Git merge before build does not work with bitbucket SCM trigger

XMLWordPrintable

      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:
      http://stackoverflow.com/questions/23203806/cloudbees-prebuild-merge-no-longer-works

      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
      touch sourceBranch.txt
      git add sourceBranch.txt
      git commit -m "Add sourceBranch.txt"
      git checkout master
      git checkout -b targetBranch
      touch targetBranch.txt
      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 git@bitbucket.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 git@bitbucket.org:elosystemsteam/paypoint-potter.git HEAD:B2-Bisque" returned status code 1:
      stdout:
      stderr: To git@bitbucket.org:elosystemsteam/paypoint-potter.git
      ! [rejected] HEAD -> B2-Bisque (non-fast-forward)
      error: failed to push some refs to 'git@bitbucket.org: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.

      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1276)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1146)

            fbelzunc FĂ©lix Belzunce Arcos
            michael_power_elotouch Michael Power
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: