Git scm fails to check the expected branch when another branch has the target branch name as a suffix

29 views
Skip to first unread message

James Robson

unread,
May 15, 2019, 4:18:05 PM5/15/19
to Jenkins Users

I have a repo with a branch called ‘develop’ and another branch called ‘kassandra/develop’. I have created a pipeline job that is building on ‘develop’, set to trigger with the ‘GitHub hook trigger for GITScm polling’.


I expect this job to run only when ‘develop’ is changed, however it is running on every commit to the repo. This seems to be because the scm polling logic is comparing the last built git hash to the git hash on ‘kassandra/develop’ (see excerpt of the polling log below).


Is this behaviour expected? Is there a way to prevent these unwanted runs?


Setup:

Git plugin: 3.9.3

git client plugin: 2.7.6


Git poll log:

[poll] Last Built Revision: Revision 576aad8bdbfbf422d6a98899fafe78cc095ebb81
 (refs/remotes/origin/develop)
<snip>
[poll] Latest remote head revision on refs/heads/kassandra/develop is: a9b4791c65f1ed2f1dc5669501fbeee58323e11e

Mark Waite

unread,
May 15, 2019, 4:28:52 PM5/15/19
to Jenkins Users
The git plugin includes support for multiple remotes (origin, upstream, downstream, etc.) and for multiple branches.  It includes guessing code for those cases where a branch name is ambiguous (like 'develop' in a repository which includes branches named 'develop', 'kassandra/develop', and 'mwaite/develop'). in the context of multiple remotes or multiple branch names.

You can often avoid the guessing by naming the branch precisely, as in 'origin/develop'.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b3d3df79-0ab9-4fd8-aeb7-1e70bc2e87ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Thanks!
Mark Waite

James Robson

unread,
May 16, 2019, 10:25:23 AM5/16/19
to Jenkins Users


On Wednesday, 15 May 2019 21:28:52 UTC+1, Mark Waite wrote:

You can often avoid the guessing by naming the branch precisely, as in 'origin/develop'.

I attempted to use 'origin/develop' as the branch name, but that causes the job to fail the checkout with "ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job". Here's the pipeline I'm testing this with:

node('linux') {
    stage
('checkout') {
        git branch
: 'origin/develop', ...
   
}
}

The last line of output before the failure is a 'git fetch' call which is identical to a run using a branch name of 'develop' which will then checkout successfully.

Mark Waite

unread,
May 16, 2019, 10:33:07 AM5/16/19
to Jenkins Users
I don't know if it will help, but you could try replacing the "syntactic sugar" command `git` with the `checkout` command.  Pipeline Syntax link on the Pipeline pages will help get the correct syntax for the details of the checkout command.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Thanks!
Mark Waite

James Robson

unread,
May 16, 2019, 11:46:51 AM5/16/19
to jenkins...@googlegroups.com
Using the `checkout` command directly does work. Using that I can specify 'origin/develop' as the branch, and the job is triggering as expected.
Thank You.

You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/oCeXFei3bZ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtG%3D8AgjqrXmZpAHBsKPr6Ep7A-ZV%2BEfTGroc46VZB%3DvVg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages