Follow the steps as mentioned below to trigger a Jenkins job automatically based on GitHub's webhook configurations: Step 1: Go to the Configuration page of the respective job and under the build trigger section, check the "GitHub hook trigger for GITScm polling" checkbox and click on the Save button.
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
.
For GitLab, use these steps:
Enter the "Build Now" URL from your Jenkins project as a Push Event URL:
http://server.com/jenkins/job/project_name/build?delay=0sec
for example
Add Web Hook
and then test hook
Then any time you commit to the repository, the web hook is triggered and a build is created. Be sure to set your Jenkins workspace to delete workspace before each build
so you get a fresh copy of the new code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With