CI with Git in Jenkins

28 views
Skip to first unread message

Roland Asmann

unread,
Mar 25, 2020, 9:39:24 AM3/25/20
to Jenkins Users
Hi everybody,

Way-back-when, Kohsuke wrote this post about how to setup CI with Git in Jenkins: https://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/

I have been using this in most my builds since and am still trying to get all colleagues to do the same (don't ask, my company can be difficult sometimes). Anyway, the other day I noticed that in one of my Jenkinsfiles, I forgot to activate the SCM polling. However, this project had been building on git pushes since the start!

Doing some testing on my own, I came to the following conclusion:
- Non-pipeline jobs all need to have the polling activated to react to the Git hook
- Single pipeline jobs also need to have polling activated
- Multibranch pipelines *don't* need to have polling activated, they just build whenever the git hook sends its request to Jenkins

Now, my question is, is this behavior correct? Does it mean that for multibranch pipelines, I *can't* NOT do CI? (Except for removing the hook, but that might influence other builds as well!) Is this actual behavior documented somewhere and did I just miss this information?

And what is now the correct way to setup CI? Should I still add the polling in my Jenkinsfile or, if I am sure I will be using a multibranch pipeline, just leave it out?

Thanks.

Roland

Mark Waite

unread,
Mar 25, 2020, 9:54:06 AM3/25/20
to Jenkins Users
Multibranch pipelines assume that you want to build all branches that include a Jenkinsfile any time the notification is received through notifyCommit or through a Web Hook.  If you do not want one or more branches built on multibranch pipelines, you'll need to exclude them.  The Basic Branch Build Strategies plugin ( https://github.com/jenkinsci/basic-branch-build-strategies-plugin/blob/master/docs/user.adoc) provides many branch selection options.

--
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/828bed5a-dda6-4782-82d9-6834b1f0e074%40googlegroups.com.

Roland Asmann

unread,
Mar 30, 2020, 12:03:44 PM3/30/20
to jenkins...@googlegroups.com
Thanks for the explanation. I do agree, I just thought it a bit weird
that there was a difference in behavior...

I still would like to know, what the consensus is to writing the
Jenkinsfile: add polling or not?

Thanks.


On 25.03.2020 14:53, Mark Waite wrote:
> Multibranch pipelines assume that you want to build all branches that
> include a Jenkinsfile any time the notification is received through
> notifyCommit or through a Web Hook.  If you do not want one or more
> branches built on multibranch pipelines, you'll need to exclude them.
> The Basic Branch Build Strategies plugin (
> https://github.com/jenkinsci/basic-branch-build-strategies-plugin/blob/master/docs/user.adoc)
> provides many branch selection options.
>
> On Wed, Mar 25, 2020 at 7:39 AM Roland Asmann <roland...@gmail.com
> <mailto:roland...@gmail.com>> wrote:
>
> Hi everybody,
>
> Way-back-when, Kohsuke wrote this post about how to setup CI with
> Git in Jenkins:
> https://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/
>
> I have been using this in most my builds since and am still trying
> to get all colleagues to do the same (don't ask, my company can be
> difficult sometimes). Anyway, the other day I noticed that in one of
> my Jenkinsfiles, I forgot to activate the SCM polling. However, this
> project had been building on git pushes since the start!
>
> Doing some testing on my own, I came to the following conclusion:
> - Non-pipeline jobs all need to have the polling activated to react
> to the Git hook
> - Single pipeline jobs also need to have polling activated
> - Multibranch pipelines **don't** need to have polling activated,
> they just build whenever the git hook sends its request to Jenkins
>
> Now, my question is, is this behavior correct? Does it mean that for
> multibranch pipelines, I **can't** NOT do CI? (Except for removing
> the hook, but that might influence other builds as well!) Is this
> actual behavior documented somewhere and did I just miss this
> information?
>
> And what is now the correct way to setup CI? Should I still add the
> polling in my Jenkinsfile or, if I am sure I will be using a
> multibranch pipeline, just leave it out?
>
> Thanks.
>
> Roland
>
> --
> 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
> <mailto:jenkinsci-use...@googlegroups.com>.
> <https://groups.google.com/d/msgid/jenkinsci-users/828bed5a-dda6-4782-82d9-6834b1f0e074%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> 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/IDXKJukzJbo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-use...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtF-Hx%3Ds5MvNssLoE5jDnzhhVu4HkuSvosNd_Y9zdoxmrA%40mail.gmail.com
> <https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtF-Hx%3Ds5MvNssLoE5jDnzhhVu4HkuSvosNd_Y9zdoxmrA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Mark Waite

unread,
Mar 30, 2020, 12:55:57 PM3/30/20
to Jenkins Users
On Mon, Mar 30, 2020 at 10:03 AM Roland Asmann <roland...@gmail.com> wrote:
Thanks for the explanation. I do agree, I just thought it a bit weird
that there was a difference in behavior...

I still would like to know, what the consensus is to writing the
Jenkinsfile: add polling or not?

Consensus is to not add polling.  The "polling must die" blog post is still applicable, even with Pipeline.  Much better to find a way to have the git repository notify Jenkins that a commit has arrived, rather than having Jenkins periodically ask if a commit has arrived.

Major git providers (GitHub, Bitbucket, GitLab, Gitea) provide web hooks that will notify Jenkins.  Many of those webhooks are even automatically managed by Jenkins.  Jenkins servers behind firewalls can use web hook routing tools to receive notifications inside the firewall from a git hosting service outside the firewall.

Mark Waite
 
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/10726501-9ed7-5d86-1147-1a83083c0a29%40gmail.com.

Roland Asmann

unread,
Apr 1, 2020, 11:04:50 AM4/1/20
to jenkins...@googlegroups.com
I'm sorry, I guess I wasn't quite clear on what I meant with this last
question.

What I want to know is if the consensus is to put the *empty* definition
of the polling in the Jenkinfile (so that configuring a single pipeline
works) even when using multibranch pipelines?
> > <mailto:roland...@gmail.com
> <mailto:jenkinsci-users%2Bunsu...@googlegroups.com>
> >     <mailto:jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-users%2Bunsu...@googlegroups.com>>.
> >     To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/jenkinsci-users/828bed5a-dda6-4782-82d9-6834b1f0e074%40googlegroups.com
> >
>  <https://groups.google.com/d/msgid/jenkinsci-users/828bed5a-dda6-4782-82d9-6834b1f0e074%40googlegroups.com?utm_medium=email&utm_source=footer>.
> >
> > --
> > 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/IDXKJukzJbo/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> > jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-users%2Bunsu...@googlegroups.com>
> > <mailto:jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-users%2Bunsu...@googlegroups.com>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtF-Hx%3Ds5MvNssLoE5jDnzhhVu4HkuSvosNd_Y9zdoxmrA%40mail.gmail.com
>
> >
> <https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtF-Hx%3Ds5MvNssLoE5jDnzhhVu4HkuSvosNd_Y9zdoxmrA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> 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
> <mailto:jenkinsci-users%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/10726501-9ed7-5d86-1147-1a83083c0a29%40gmail.com.
>
> --
> 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/IDXKJukzJbo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-use...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtHc8fTMno-uBSEv66djzVc-AjeYtid77K%3Dp11qqCB1QuA%40mail.gmail.com
> <https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtHc8fTMno-uBSEv66djzVc-AjeYtid77K%3Dp11qqCB1QuA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Mark Waite

unread,
Apr 1, 2020, 12:10:07 PM4/1/20
to Jenkins Users
I has assumed that was what you meant.  I assumed the question was, "Should I specify a (possibly empty) polling interval in the Jenkinsfile on the branches of my multibranch pipeline?"  My answer is, no, use web hooks as the better solution.

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/b2b1aeb8-12aa-90b6-f6cf-3f59485ff3aa%40gmail.com.
Reply all
Reply to author
Forward
0 new messages