How can I make Jenkins CI with Git trigger on pushes to master?
As already noted by gezzed in his comment, meanwhile there is a good solution (described in Polling must die: triggering Jenkins builds from a Git hook):
Set the Jenkins job's build trigger to Poll SCM, but do not specify a schedule.
-
Create a GitHub post-receive trigger to notify the URL
http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>?token=<get token from git to build remotely>
This will trigger all builds that poll the specified Git repository.
However, polling actually checks whether anything has been pushed to the used branch.
It works perfectly.
As of version 0.5, the GitHub plugin for Jenkins can trigger a build when a change is pushed to GitHub.
Instead of triggering builds remotely, change your Jenkins project configuration to trigger builds by polling.
Jenkins can poll based on a fixed internal, or by a URL. The latter is what you want to skip builds if there are not changes for that branch. The exact details are in the documentation. Essentially you just need to check the "Poll SCM" option, leave the schedule section blank, and set a remote URL to hit JENKINS_URL/job/name/polling.
One gotcha if you have a secured Jenkins environment is unlike /build
, the /polling
URL requires authentication. The instructions here have details. For example, I have a GitHub Post-Receive hook going to username:apiToken@JENKIS_URL/job/name/polling
.