-
Bug
-
Resolution: Unresolved
-
Minor
-
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.
Possible duplicate of https://issues.jenkins-ci.org/browse/JENKINS-50168 ?
The solution there is different, but the symptom seems very similar