stash-jenkins-postreceive-webhook icon indicating copy to clipboard operation
stash-jenkins-postreceive-webhook copied to clipboard

Using git webhook, jenkins run build when code pushed to specific Branch

Open guruvamsichintala opened this issue 8 years ago • 10 comments

I have scenario where I have two branches B1 and B2. I have configured two jobs in Jenkins which builds those branches when something is pushed to github. Right now even though some one pushed code into B1, jenkins runs both the jobs as webhook triggered jenkins with code push. Is there a way I can run jenkins job using git webhook where B1 job must run only when git receives push for B1

guruvamsichintala avatar Dec 02 '16 20:12 guruvamsichintala

I am having the same issue. Any solutions?

RishabhTayal avatar Dec 16 '16 18:12 RishabhTayal

On github, instead of jenkins-github plugin , used jenkins-git plugin with url " http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository> ". Then in the jenkins jobs changed the build trigger to Poll SCM , but do not specify a schedule instead of Build when a change is pushed to GitHub.

Follow the link: http://stackoverflow.com/questions/5784329/how-can-i-make-jenkins-ci-with-git-trigger-on-pushes-to-master

guruvamsichintala avatar Dec 18 '16 02:12 guruvamsichintala

@Guruvamsichintala how does it trigger build only on a specific branch?

RishabhTayal avatar Dec 18 '16 02:12 RishabhTayal

As you configured the "notifycommit url" and jenkins jobs to poll, Git notifies jenkins when code is pushed. Then it checks all the jobs with poll and checks if any job is configured with changed branch and triggers it.

guruvamsichintala avatar Dec 18 '16 02:12 guruvamsichintala

@guruvamsichintala we are not using this plugin on Github. It's on stash server(aka bit bucket server).

RishabhTayal avatar Dec 19 '16 16:12 RishabhTayal

What do your jenkins jobs configurations look like? I have the same setup (we actually have 1 job per branch). If someone modifies master (by a commit) it doesn't trigger the jobs using a different branch.

thrownullpointer avatar Jun 23 '17 01:06 thrownullpointer

earlier we configured "build when pushed to git repository" in build triggers which didn't work. All the jobs used to trigger build even though a code is pushed to single branch. Now we changed the build trigger to "Poll SCM" without any schedule and change the plugin on github that notifies jenkins, which works. How are your jenkins jobs configured? Are you using jenkinsfile and paced it on github to notify ?

guruvamsichintala avatar Jun 23 '17 13:06 guruvamsichintala

Ran into issues with this and it seemed like the only way around it was to use a fork workflow instead of a clone workflow. hoping to revisit this.

raptordzuricsko avatar Aug 28 '17 22:08 raptordzuricsko

@raptordzuricsko Does #172 fix your problem? I'm currently testing it for a merge.

alexBraidwood avatar Aug 29 '17 01:08 alexBraidwood

I believe it does. you are a hero alexBraidwood !

raptordzuricsko avatar Aug 29 '17 17:08 raptordzuricsko