Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to trigger a build for a branch only when there is a checkin to that branch

Tags:

git

jenkins

We have 10-15 git branches but we only want to trigger Jenkins jobs on 2 of these ("master" and "beta1"). I am using the Git Plugin for Jenkins and specifying both "master" and "beta1" in the "branches to build" section. I am also specifying ${GIT_BRANCH} in the "Local subdirectory for repo (optional)" field.

I want to trigger the Jenkins job only on the master branch only when a checkin appears on the master branch.

I want to trigger the Jenkins job only on the beta1 branch only when a checkin appears on the beta1 branch.

I want both of these branches controlled by the same Jenkins job so that the build number will be unique between the 2 branches (if they were in 2 different jobs, the build numbers could be the same).

Currently, it seems to be triggering a job on beta1 branch for a checkin from master branch. From the logs (Note: the change triggered as reported in the first line in the log below is from the master branch):

Started by remote host (IP) with note: Triggered by push of revision e4391d0049ff: "blah" to (URL) by (USER)
Building in workspace /var/lib/jenkins/jobs/Orca/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Orca/workspace - hudson.remoting.LocalChannel@3ae1a582
Using strategy: Default
Last Built Revision: Revision 7e2aae6c752a16516d9f6ac48944492a4e3596d4 (origin/master)
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository (SSH)
git --version
git version 1.7.4.1
Fetching upstream changes from origin
Cleaning workspace
Resetting working tree
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/beta1
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/(BLAH)
Seen branch in repository origin/master
Seen branch in repository origin/(BLAH)
Seen 22 remote branches
Multiple candidate revisions
Scheduling another build to catch up with Orca
Commencing build of Revision eaad42c836a87672c546d61f310cc31bf03ecb97 (origin/beta1)
Checking out Revision eaad42c836a87672c546d61f310cc31bf03ecb97 (origin/beta1)
like image 435
Andrew McElroy Avatar asked Sep 16 '13 21:09

Andrew McElroy


1 Answers

If you are doing this:

specifying both "master" and "beta1" in the "branches to build" section

and you are triggering the build based on polling Git, then Jenkins is going to trigger the job when it finds changes in either of these branches. That's the intended functionality, and the configuration you're looking for is not supported to my knowledge.

I can suggest two possible solutions:

  1. Use two separate Jenkins jobs. This is how we do it, and if we need to keep build numbers discrete then we just separate the build numbers by a large number. You can set the next build number to 300,000 on one of the jobs, for example.

  2. Create two jobs, one that tracks each branch but doesn't actually build anything. Use the Parameterized Trigger Plugin to trigger the same downstream job with the Git branch parameter.

like image 188
curtiskline Avatar answered Nov 17 '22 21:11

curtiskline