Trigger the Jenkins job using Github Webhook

Naren Chejara
3 min readMay 20, 2019

--

“Jenkins is an open-source automation server written in Java. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitation technical aspects of continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat”Wikipedia

I presume that you have a basic understanding of Jenkin installation, Manage plugin, create a build, etc. Read Create Jenkins Job and Clone Repository from Github story in case you are not

By the end of this article, You will have a good understanding of the following

  1. Install plugins
  2. Create a FreeStyle build
  3. Configure GIT source code management
  4. Configure GITHUB Webhook

Let’s get started!

Install Plugins

Jenkin is an open-source and there are numbers of plugins that have been published by the Jenkins community. We need to install the GitHub Integration Plugin plugin.

Go to Manage Jenkins → Manage Plugins → Available tab and search GitHub Integration Plugin

Install the plugin (Plugin will automatically install all its dependencies)

Tips #1: Search action shows empty result if the plugin has already installed.

Tips #2: Do not forget to install GIT on the machine else git actions will not be success!

Create The FreeStyle Job

Creating a FreeStyle job is effortless in Jenkin, Navigate to Jenkin home page and click on the New Item from the left navigation section. Configure a build name and choose Freestyle Project and hit an OK button (Refer to the image below). Jenkin created a build and redirect to the configuration page.

Create a freestyle job in Jenkins

Configure GIT source code management

Go to Source Code Management Tab and choose Git options. configure git repository URL and branch. Checked GitHub hook trigger for GITScm polling option and hit the save. Refer an image below for reference

Configure GITHUB Webhook

Git Hub Webhook allows external services to be notified when certain events happen. When the specified event happened, Git Hub sends a POST request to the configured URL.

Go to the Settings page in your GitHub repository, select Webhooks and click on Add webhook button.

Configure the following settings as per your requirements

  1. Payload URL: Add your Jenkin hostname (make sure the hostname is accessible by the GitHub) and append /github-webhook/. For Example http://my-jenkin-host.com/github-webhook/
  2. Content-type: select an application/JSON type
  3. Which events would you like to trigger this webhook? select “Just the push event” this will trigger this webhook when anyone pushes any change in the repository. In this article, I want to trigger a webhook on each push so I selected the default option but you are free to choose any other event like Forks, Pull request, Commit comments, etc. by selecting “Let me select individual events.
  4. Active: This means the webhook status is active and will deliver event details when this hook is triggered.
Configure and Add webhook

You will see the test ping request was successfully sent to the Jenkin server if everything configured correctly.

Test ping request success

All the configuration has done, Now Jenkin build will be triggered automatically when a new changes push in the repository.

If you enjoyed this story, please hit the like button and share it to help others find it.

--

--

Naren Chejara
Naren Chejara

Responses (3)