top of page

Jenkins Triggers Github with Webhook

Updated: Jun 23, 2023

Continuous Integration (CI) is the DevOps (development and operations) practice for Software Development as it automates the testing, development, and deployment process in a fast-paced environment. Companies use DevOps to optimize their development and deployment processes. To implement Continous Integration in your project, you need to integrate your SCM (Source Control Management) tool with a CI tool.


Jenkins is an open-source CI tool used by many Developers to automate the testing and deployment of their applications. Jenkins GitHub Webhook allows Developers to save time and keep the project updated all the time. GitHub is one of the widely used SCM tools used for version control and allows Developers to collaborate with other Developers worldwide.

Jenkins GitHub Webhook is used to trigger the action whenever Developers commit something into the repository. It can automatically compile or deploy applications if there are no errors detected. In this article, you will learn the steps to set up Jenkins GitHub Webhook. You will also read about the benefits of the Jenkins GitHub Webhook and how it helps Developers automate tasks.


Prerequisites

  • An active GitHub account.

  • Jenkins installed on the operating system.


Introduction to Jenkins

Jenkins Triggers Github with Webhook

Jenkins is an open-source tool entirely built in Java that provides Continuous Integration (CI) for Software or Application Development. It automatically executes a series of actions or events that allows seamless ongoing development, testing, and deployment of newly created code. Whenever a developer commits changes to a code from a repository, Jenkins automatically triggers defined actions.

Jenkins helps Developers continuously work on a project and improving it. Jenkins is one of the most used DevOps tools because it is open source and has strong community support. There are many plugins available in the market that makes Jenkins more powerful and adds capabilities to it.

Jenkins elements work together in the following manner, as shown below:

  • Developers make changes to the existing code available in the shared repository.

  • Jenkins server continuously checks for any change in the repository at regular intervals. Once any commit is made, Jenkins detects it.

  • The Build Server builds the code into an executable file. If the build fails, Developers receive feedback for a particular commit.

  • Jenkins deploys the application to the test server, and if it fails, the Developers get notified.

  • If every process goes error-free, then the application is deployed to the production server.

Key Features of Jenkins

Jenkins is a widely used tool for Continuous Integration in DevOps and helps Developers to make continuous changes to the application. A few features of Jenkins are listed below:

  • Easy Distribution: Jenkins is built using Java. It can distribute work across multiple machines to deliver faster testing, deployment, and build features to many platforms.

  • Easy Installation: Jenkins is independent of the platform because it is developed in Java. One can easily install it on Windows, Linux/ Unix, or macOS and configure it with its web interface.

  • Ready Plugins: Jenkins can extend its features and capabilities using plugins. There are many plugins available for Jenkins that help Developers ease the development process.

To learn more about Jenkins, click here.


Introduction to GitHub

Jenkins Triggers Github with Webhook

GitHub is a web-hosting service for version control and Software Development collaboration platforms. It offers several other functionalities such as bug tracking, feature requests, task management, Continuous Integration. Github allows Developers to collaborate with other Developers and work on shared project repositories. With the help of its version control feature, Developers can save different previous versions of the project source code that eliminates the process of making copies of each version control locally.


Key Features of GitHub

GitHub helps Developers maintain version control and optimizes the entire Software Development ecosystem. A few features of GitHub are listed below:

  • Profile Showcasing: GitHub allows Developers to upload their projects on a platform and set it public to let other people view developer’s profiles. Many companies use GitHub profiles to evaluate the skill set of any developer at the time of hiring.

  • Integrations: GitHub offers integration with many 3rd party tools and apps to let users sync data and optimize the workflow. It also integrates with code editors to manage the repository from the editor.

  • Project Management: GitHub allows companies to keep track of all the Software Development progress and collaborate with team members.

To learn more about GitHub, click here.


Steps to Set Up Jenkins GitHub Webhook

Now that you have a good understanding of Jenkins and GitHub. In this section, you will learn about the steps to set up Jenkins GitHub Webhook. The following steps are listed below:

  • Step 1: Configuring Jenkins for GitHub

  • Step 2: Setting Up GitHub Webhook

Step 1: Configuring Jenkins for GitHub

  • Log in to Jenkins.

  • Click on the “New Item” option to create a new job, as shown in the image below.

Jenkins Triggers Github with Webhook
  • Then, select the “Freestyle Project” option and click on the “Ok” button, as shown in the image below.

Jenkins Triggers Github with Webhook
  • It will open the configurations for the new Jenkins GitHub Webhook project you just created.

  • Go to the “Source Code Management” tab to change the settings for Jenkins GitHub Webhook.

  • Scroll down and under the “Source Code Management” section, choose the “Git” option to let Jenkins know that the new job is for Jenkins GitHub Webhook.

  • Log in to your GitHub account.

  • Open the repository that you want to sync with Jenkins for Continous Integration.

  • Go to your GitHub account and copy the URL of your repository from the address bar of the browser.

  • Switch back to your Jenkins GitHub Webhook tab and paste the URL in the field of “Repository URL“, as shown in the image below.

Jenkins Triggers Github with Webhook
  • Now, go to the “Build Triggers” tab where you can configure what action Jenkins GitHub Webhook should perform if any change is detected by Jenkins in the GitHub repository.

  • Here, choose the “GitHub hook trigger for GITScm pulling” option, which will listen for triggers from the given GitHub repository, as shown in the image below.

Jenkins Triggers Github with Webhook
  • Now, click on the “Apply” button to save the changes and create a new Jenkins GitHub Webhook for your repository.

Step 2: Setting Up GitHub Webhook

  • Switch to your GitHub account.

  • Now, go to the “Settings” option on the right corner, as shown in the image below.

Jenkins Triggers Github with Webhook
  • Here, select the “Webhooks” option and then click on the “Add Webhook” button, as shown in the image below.

Jenkins Triggers Github with Webhook
  • It will provide you the blank fields to add the Payload URL where you will paste your Jenkins address, Content type, and other configuration.

  • Go to your Jenkins tab and copy the URL then paste it in the text field named “Payload URL“, as shown in the image below.

Jenkins Triggers Github with Webhook
  • Append the “/github-webhook/” at the end of the URL.

  • The final URL will look like in this format “http://address:port/github-webhook/“.

  • Select the “Content type” to “application/json” format, as shown in the image below.


Jenkins Triggers Github with Webhook
  • The “Secret” field is optional. Let’s leave it blank for this Jenkins GitHub Webhook.

  • Next, choose one option under “Which events would you like to trigger this webhook?“. The 3 options will do the following events listed below:

    • Just the Push Event: It will only send data when someone push into the repository.

    • Send Me Everything: It will trigger, if there is any pull or push the event into the repository.

    • Let Me Select Individual Events: You can configure for what events you want your data.

  • Now, click on the “Add Webhook” button to save Jenkins GitHub Webhook configurations.

That’s it! You completed Jenkins GitHub Webhook. Now for any commit in the GitHub repository, Jenkins will trigger the event specified.

Benefits of Jenkins GitHub Webhook

Jenkins GitHub Webhook provides an environment for Continuous Integration (CI) and is widely used in the DevOps process. A few benefits of Jenkins GitHub Webhook are listed below:

  • Jenkins GitHub Webhook makes the development process faster as it allows Developers to automatically perform a specified action when any commit is done to the source code.

  • It helps Developers detect issues and resolve them almost right away which keeps the application in a state to deploy safely.

  • Jenkins GitHub Webhook automates the build, test, and deployment of projects on any platform.


Conclusion

In this article, you learnt the steps to set up Jenkins GitHub Webhook. You also read about the benefits of using Jenkins GitHub Webhook in Software Development and how it helps Developers save time. Jenkins helps Developers to trigger some actions or events, and GitHub allows them to maintain version control. Companies need Jenkins GitHub Webhook to optimize their Software Development.


160 views0 comments

Related Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
Stationary photo

Be the first to know

Subscribe to our newsletter to receive news and updates.

Thanks for submitting!

Follow us
bottom of page