How to whitelist the branches to be built upon git hook notification

104 views
Skip to first unread message

Francois Marot

unread,
Mar 9, 2016, 3:25:31 PM3/9/16
to Jenkins Users
Hello all jenkins users,

I'd like to have some advice on the best way to have a git hook triggering a job but only for some branches (hence the notion of "whitelisted branched").

The use case is that some old branches are not buildable by the job. Only some recent branches are. BUT some commit may be made to the old branches because we have to support old version of the software.

I would not like those commit to trigger my job.

I have a few possibilities but none suits me well:
- creating one job per branch to be built. That's a huge overhead and not maintainable
- configure the git hook not to trigger jenkins for the old branches. Simple BUT jenkins will still try to build the old branches once commit are made into them and a recent branch triggers the job (as by default the Jenkins git plugin builts all branches where commits have been made since the last job execution)
- configure the regexp for the branch to be built. I, hum... regexp... well.. no thanks ;)
- start a convention on branch naming (with a specifix prefix or suffix) so I can easily configure the regexp. It may be the best idea yet but some existing branches that have to be built do not match any convention.

So unless someone points me to a whitelist kind of filter for branches to be built, I think I 'll go with the last solution. Any idea ?

Regards
François

Mark Waite

unread,
Mar 9, 2016, 3:36:30 PM3/9/16
to Jenkins Users
You might consider the "pipeline plugin".  It includes a multi-branch facility which will automatically configure a new job for any branch which has a "Jenkinsrule" file defined at the root of that repository.  I've found it very helpful to allow me to add and remove jobs from my setup just by adding or removing a Jenkinsrule file which contains the job definition.

I only recently started using this based on the tutorial at https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md .  It isn't as full featured as a typical job definition, but it is very elegant for its simplicity in defining jobs easily from multiple branches of a repository.

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/ab18f096-ca0b-4bb6-a02f-82f9da6cb4f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Francois Marot

unread,
Mar 10, 2016, 5:58:01 AM3/10/16
to Jenkins Users
Hi Mark,

thanks for your answer.
In fact I've just found a very straightforward method to do it so I won't use what you suggested. Thanks nevertheless !
Here is how to do it:

in the Jenkins Git plugins config part of my job, I added the "Additionnal Behavior" "Strategy for choosing what to build". Then the "Choosing strategy" I selected is "Ancestry". This way, the build is triggered only for the branches which have a common commit ancestry whose SHA-1 is specified.

For those interested here is a capture of the config gui:

http://imgur.com/nheNJlX

Baptiste Mathus

unread,
Mar 11, 2016, 6:22:18 AM3/11/16
to jenkins...@googlegroups.com


Le 9 mars 2016 9:36 PM, "Mark Waite" <mark.ea...@gmail.com> a écrit :
>
> You might consider the "pipeline plugin".  It includes a multi-branch facility which will automatically configure a new job for any branch which has a "Jenkinsrule" file

Nitpicking for future reference: that file is actually named Jenkinsfile.

-- Baptiste

Reply all
Reply to author
Forward
0 new messages