Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Jenkins build based on a new GitHub release or commit to the master branch

I realize this question has been asked before here, here, and here, but none of these solutions appears to be working for my Jenkins setup and I can't figure out why.

My objective is to trigger a Jenkins build when either a new commit is made to the master branch or when any tag (or in GitHub, a release) is added to the repo. Here's my current setup:

enter image description here

When I make a new commit to the master branch, a new build is triggered. But when I add a new GitHub release, nothing happens.

Looking at my "Git Polling Log" shows the following output:

Started on Jun 20, 2017 1:25:00 AM
Polling SCM changes on master
Using strategy: Default
[poll] Last Built Revision: Revision 035c0f46422616b1862376b79c43b2562dc66f93 (origin/master)
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repositories
 > git config remote.origin.url [email protected]:some-org/sample-app-frontend.git # timeout=10
Fetching upstream changes from [email protected]:some-org/sample-app-frontend.git
 > git --version # timeout=10
using GIT_SSH to set credentials GitHub SSH Key
 > git fetch --tags --progress [email protected]:some-org/sample-app-frontend.git +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/remotes/origin/tags/*
Polling for changes in
Seen branch in repository origin/master
Seen branch in repository origin/tags/stage-v0.0.1
Seen branch in repository origin/tags/stage-v0.0.2
Seen branch in repository origin/tags/stage-v0.0.3
Seen branch in repository origin/tags/v0.0.4
Seen branch in repository origin/tags/v0.0.5
Seen branch in repository origin/tags/v0.0.6
Seen branch in repository origin/tags/v0.0.7
Seen 8 remote branches
 > git tag -l # timeout=10
 > git rev-parse refs/tags/stage-v0.0.2^{commit} # timeout=10
 > git rev-parse refs/tags/v0.0.7^{commit} # timeout=10
 > git rev-parse refs/tags/stage-v0.0.1^{commit} # timeout=10
 > git rev-parse refs/tags/v0.0.6^{commit} # timeout=10
 > git rev-parse refs/tags/v0.0.5^{commit} # timeout=10
 > git rev-parse refs/tags/v0.0.4^{commit} # timeout=10
 > git rev-parse refs/tags/stage-v0.0.3^{commit} # timeout=10
Done. Took 0.2 sec
No changes

Note that I'm using git polling once per minute. So it appears that git correctly detects the new branches, but somehow the git polling Jenkins is doing does not think a new branch qualifies as a "change" since it keeps reporting "No changes" at the bottom.

like image 958
Josh Padnick Avatar asked Oct 18 '22 10:10

Josh Padnick


1 Answers

I have searched on this for sometime and was able to figure out the solution for triggering the jenkins job when tag is released from git hub. Here is the screenshot. Select advanced option from where git repositories are given and configure the details as below. So when release is tagged the jenkins job is triggered.

Refspec value should be +refs/tags/*:refs/remotes/tags/*.

enter image description here

like image 64
siri Avatar answered Oct 20 '22 22:10

siri