Have you ever tried adding GitHub webhook in Jenkins?? In this blog, I will be demonstrating the easiest way to add a webhook in our pipeline.
First, let’s see what is a webhook??
The concept of a WebHook is simple. A WebHook is an HTTP callback: an HTTP POST that occurs when something happens. GitHub webhooks in Jenkins is used to trigger our build whenever a developer commits something on the master branch.
Let’s see how to add build a Webhook in GitHub and then add this webhook in Jenkins.
- Go to the project repository.
- Go to settings on the right corner.
- Click on webhooks.
- Click Add webhooks.
- Write the Payload URL
Payload URL:- Is the URL where our Jenkins is running.
Content type:- The kind of data we want in our webhook. JSON, XML, etc.
Secret:- Used to secure our webhook we can provide a secret in our webhook and ensure that only applications having this webhooks can use it.
SSL verification:- This SSL Checker will help us diagnose problems with SSL certificate installation. We can verify the SSL certificate on our web server to make sure it is correctly installed, valid, trusted and doesn’t give any errors to any of our users.
When shall these webhooks be triggered?
- Just the push event:- Only send data when someone pushed into my repository.
- Send me everything:- If there is any pull or push event in our repository we will get notified.
- Let me select individual events:- We can configure for what events we want our data.
Click Create and a webhook will be created.
But there is a problem, we have to take care of if we are running Jenkins on localhost then writing
https://localhost:8080/github-webhook/ will not work because webhooks can only work when they are exposed to the internet.
So, if we want to make our localhost to be exposed to the internet then we can use the ngrok tool. Refer to this link.
Now let’s see how to use this webhook into our Jenkins.
- Go to Manage Jenkins ->Configure System
- On scrolling down, we will find GitHub Pull Requests checkbox.
In Published Jenkins URL:- add the repository link
- Click on Save.
Now go to Jenkins Pipeline and select GitHub hook trigger for GITScm polling.
In this way, we can add Webhook to our job and ensure that everytime a developer commits code to GitHub our build will get triggered.
I hope this blog was helpful in adding Github webhook in Jenkins.