Jenkins git commit for specific branch triggers build jobs for other branches too

1,368 views
Skip to first unread message

Siddharth Bhaskar

unread,
Aug 7, 2015, 5:40:32 PM8/7/15
to Jenkins Users

We have a internal enterprise Github repo, and i have multiple feature branches. I am facing a issue with triggering a build on a specific branch. I have configured jobs for each of the feature branches. There is one jenkins job for one feature branch. The first time i commit a code, it also triggers builds for jobs with other branches.


Steps to reproduce the problem:

1.We have a internal Github for enterprise. For my repo, i have setup webhook for github as below

 Settings -> Webhooks & Services -> Services
 Select Jenkins (GitHub plugin) 
 Jenkins Hook Url: http://************/jenkins/github-webhook/

2.For my 3 branches in github repo : branch1, branch2, branch3, i created three jobs in jenkins:Job1, Job2, Job3 with SCM configured as below

Source Code Management:
Repo URL: git@********/********.git
Branches to Build: refs/heads/BRANCH_NAME

Build Trigger: Build when a change is pushed to GitHub

3.On committing code to my branch : branch1. It triggers all the 3 jobs in jenkins: Job1, Job2, Job3. Note:This is the first time that the jobs were triggered.

4.On committing code for the second time to branch: branch1. It triggers only Job1 in jenkins.


It looks like first time all jobs are getting executed for the repo, irrespective of the branch.

Details on my jenkins setup: Jenkins Version: 1.565.1, GitHub plugin: 1.9.1


Any help/guidance to solve this issue is appreciated.

Please let me know if i missed any details


FYI: I tried steps listed http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/

Mark Waite

unread,
Aug 7, 2015, 6:08:00 PM8/7/15
to Jenkins Users
When you say "This is the first time the jobs were triggered", I think you mean that the jobs were defined and had not yet run.  If that is the case, then I think the behavior you're seeing seems reasonable.  

The webhook causes the jobs to poll the repo.  The poll of the repo shows that there are changes on each of those branches which have not yet been built.  When there are changes on a branch which have not been built, the job runs to build those changes.  Once those changes are built, future checks for changes on that branch will see that there are no changes to be built.

It may be possible to limit the start of polling to only specific branches by passing a "branch=your_branch_name" parameter with the webhook, but I don't have experience with that yet.

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/e1f9b736-fbd8-45a9-a949-18d396d870cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Siddharth Bhaskar

unread,
Aug 7, 2015, 6:35:18 PM8/7/15
to Jenkins Users
Thanks Mark for your response.

Yes, you are correct, the jobs were defined but not run yet.

The build trigger is on git push. If i have webhook for a commit on one branch, it starts the build for other branches too. 
I wish there was a way for job to find that the webhook was for a commit on another branch and not trigger the build.

We have a automation tool which creates jenkins jobs for branches on demand. And after job is run the artifact is uploaded in the artifact repo. We want to avoid this, unless checkin was for that branch.

I will explore the webhook for passing branch names. I guess this will limit the posts from github to jenkins. I do want posts from github for other branches.
Thanks for your help

Mark Waite

unread,
Aug 7, 2015, 9:26:43 PM8/7/15
to Jenkins Users
If you're creating the jobs dynamically, but don't want them built the first time, could you delay the creation of the job until the point where you want them built?

Reply all
Reply to author
Forward
0 new messages