How to Add Github Webhooks to a Jenkins Pipeline
Trigger the execution of Jenkins jobs based on GitHub events
Github provides a handy way to call webhooks’ URLs when certain events are triggered. The list of these events is long and includes: on pushing to a repository, on a pull request opening, closing, and reopening, on creation of a release, and many more. You can check the complete list here.
To make it simple, Github will perform a POST request with a payload object contains data about the triggered event to your defined webhook URL once the event is triggered. This will allow us to automate the executions of some actions based on the Github events. For example, if after each push to the master branch we want to package or deploy our software, we can simply add a webhook to the Jenkins task responsible for packaging or deploying the service.
In this post, I’ll show how we can define a Jenkins webhook and how to defile the Jenkins task that is linked to the Github webhook.
Adding Jenkins Webhook in Github
- Open Github repository.
- Go to “settings” and then to “hooks”.
- Click the “Add webhook” button.
- Fill in the form, as shown in the image below. For the payload URL, provide your Jenkins URL and the GitHub webhook path at the end of the URL —
https://${jenkins_url}/github-webhook/. You can disable SSL verifications if you don’t have a valid SSL cert for your Jenkins server. Finally, choose the option “Calling the webhook only for push events.” (This actually depends on what you are trying to do. You can change this by selecting other options).

5. Finally, when all the changes have been made, click on “Add webhook”
Building a Jenkins Pipeline to Handle the Webhook Call
- Make sure you’ve installed the Github plugin and configured it on Jenkins. To configure the plugin you need to go the Jenkins
Configure systempage, scroll down to the GitHub section add a new GitHub instance, as shown:

2. The next step is to start writing the pipeline. The first line configures it to run whenever Jenkins receive push notifications from GitHub:
properties([pipelineTriggers([githubPush()])])
3. The next step is to configure the pipeline to be executed for the Github repository. This can be done by adding a checkout stage at the beginning of your pipeline. One important thing to note is that the url and branches attributes must be static values and can’t include any kind of variables.





