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

Triggers on wrong branch when pushing multiple merges

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • git-plugin
    • None
    • Jenkins 2.138.3
      Git Plugin 2.7.3
      Windows 2012
      Chrome

      We use Bitbucket Server for source control. We have three permanent branches: develop, release, master. We have automatic merges turned on so that for any PR/merge into the release branch, Bitbucket will merge release into the develop branch. For any PR/merge into the master branch, Bitbucket will merge master into release and develop. Bitbucket is configured to always create a new merge commit.

      After the merge, Bitbucket sends a commit notification to Jenkins. In the situation of a merge into release, two notifications are sent: one for the merge into release and another for the automatic merge into the develop branch.

      When the git plugin polls for what branches are included in the merge to release commit , it sees both the develop and release branch instead of just the release branch. It looks like the Git plugin is using -contains instead of -points-at to determine what branch a commit points to.

      Steps to Reproduce:

      1. Create a repo.
      2. Create a develop branch. Make a commit on that branch.
      3. Make a release branch.
      4. Make a new commit on the develop branch. Merge it into the release branch.
      5. Merge the release branch into the develop branch. `git log -2 --graph` should look something like this:

      *   commit e00fb35bcd9b7fc218f0c6b7aec352d7ad1fb62e (HEAD -> develop, tag: 2019.110.100, origin/develop, origin/HEAD)                        
      |\  Merge: a251303 366bf67                                                                                                                   
      | | Author: ********                                                                                                
      | | Date:   Thu Jan 10 10:34:48 2019 -0800                                                                                                   
      | |                                                                                                                                          
      | |     Automatic merge from release -> develop                                                                                              
      | |                                                                                                                                          
      | |     * commit '366bf67833c09f8d09280d8ec31b8142dfd5c43f':                                                                                 
      | |                                                                                                                                          
      | *   commit 366bf67833c09f8d09280d8ec31b8142dfd5c43f (tag: 2019.110.99, origin/release)                                                     
      | |\  Merge: 60db8dd a251303                                                                                                                 
      | |/  Author: ********                                                                                              
      |/|   Date:   Thu Jan 10 10:34:48 2019 -0800                                                                                                 
      | |                                                                                                                                          
      | |       Merge pull request #11 from develop to release                                                           
      | |                                                                                                                                          
      | |       * commit 'a251303c15524fad76d3634834ffe6b8aec51dbe':                                                                               
      | |                                                                                                                                          
      

      6. Create a Jenkins freestyle job that polls your repository but doesn't actually poll the repository. Set the branches to build to origin/**.
      7. Make a notifyCommit web request for the merge to release commit: https://*******/git/notifyCommit?url=ssh://git@******/*******.git&branches=release&sha1=366bf67833c09f8d09280d8ec31b8142dfd5c43f
      8. Note that the plugin reports the build happening on the develop branch instead of the release branch. I would expect (and want) the build to run on the release branch.

      I think the problem is with the command to determine what branches a commit points to. The plugin is currently using:

      git branch -a -v --no-abbrev --contains 366bf67833c09f8d09280d8ec31b8142dfd5c43f
      

      I believe it should be using:

      git branch -a -v --no-abbrev --points-at 366bf67833c09f8d09280d8ec31b8142dfd5c43f
      

      to get only the branch heads of a commit. From the Git docs: "--contains <commit> is used to find all branches which will need special attention if <commit> were to be rebased or amended, since those branches contain the specified <commit>." I'm not sure if what the Git plugin is doing would be considered "finding all branches which will need special attention" in case of a rebase/amend.

      Please update the Git plugin to use the -points-at argument instead of the -contains parameter.

          [JENKINS-55524] Triggers on wrong branch when pushing multiple merges

          andrew lorien added a comment -

          Possible duplicate of https://issues.jenkins-ci.org/browse/JENKINS-50168 ?

          The solution there is different, but the symptom seems very similar

           

          andrew lorien added a comment - Possible duplicate of https://issues.jenkins-ci.org/browse/JENKINS-50168 ? The solution there is different, but the symptom seems very similar  

          Aaron Jensen added a comment -

          Not a duplicate. This is a different issue.

          Aaron Jensen added a comment - Not a duplicate. This is a different issue.

          ovi craciun added a comment -

          we are seeing this behavior
          1. we have a project with "Build when a change is pushed to BitBucket" checked and "Branch Specifier (blank for 'any') " as origin/development. This one works as expected.
          2. we have a second project with "Build when a change is pushed to BitBucket" checked and "Branch Specifier (blank for 'any') " as origin/master. This project is triggered for any commit to any branch.
          the only difference between the two projects is the branch it is supposed to build.

          ovi craciun added a comment - we are seeing this behavior 1. we have a project with "Build when a change is pushed to BitBucket" checked and "Branch Specifier (blank for 'any') " as origin/development. This one works as expected. 2. we have a second project with "Build when a change is pushed to BitBucket" checked and "Branch Specifier (blank for 'any') " as origin/master. This project is triggered for any commit to any branch. the only difference between the two projects is the branch it is supposed to build.

          Mark Waite added a comment -

          splatteredbits recommends using --points-at instead of --contains. I think that seems like a reasonable idea though it will require special handling for the cases where the command line git version is 2.6.0 or older (CentOS 6, CentOS 7, Red Hat Enterprise Linux 6, Red Hat Enterprise Linux 7, and likely several others). Thankfully, Ubuntu 16 and Debian 9 both include a command line git version that supports the --points-at argument.

          Mark Waite added a comment - splatteredbits recommends using --points-at instead of --contains . I think that seems like a reasonable idea though it will require special handling for the cases where the command line git version is 2.6.0 or older (CentOS 6, CentOS 7, Red Hat Enterprise Linux 6, Red Hat Enterprise Linux 7, and likely several others). Thankfully, Ubuntu 16 and Debian 9 both include a command line git version that supports the --points-at argument.

            Unassigned Unassigned
            splatteredbits Aaron Jensen
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: