Auto Trigger Jenkins Jobs Using Github Webhook


Auto Trigger Jenkins Jobs Using Github Webhook



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

GitHub webhooks are an automated way to receive data delivery to your server whenever specified (or configured) events occur. Webhooks connect two applications and send serialized data to the configured application when a specific event triggers on the Guthub.

I presume that you are familiar with a basic understanding of Jenkin installation, Manage plugin, create a build, etc. At the end of this story, You will have a good understanding of the following.


  1. Install plugins
  2. Create a FreeStyle build
  3. Configure SCM (Git) in Jenkins Job
  4. Configure Jenkins Server in GitHub Webhook


Let us 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, do the following to install Github plugin.

  • Go to Manage Jenkins --> Manage Plugins --> Available tab and search GitHub Integration Plugin. The search result will be empty if the plugin has already installed.

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


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 SCM (Git) in Jenkins Job


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 SCM in Jenkins Job


Configure Jenkins Server in GitHub Webhook

GitHub 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.

Github webhook configuration


Configure the following settings as per your requirements

  • 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/

  • Content-type:

    Select an application/JSON type.

  • 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.

  • Active:

    This means the webhook status is active and will deliver event details when this hook is triggered.

Configure jenkins server in Github webhook


Once everthing configured correctly, a ping request is send to Jenkins server as shown in the below image.

Ping request to server from Github webhook


Thats It!, The Jenkin job will be triggered automatically when a new changes push in the repository.