DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Adding a GitHub Webhook in Your Jenkins Pipeline

Adding a GitHub Webhook in Your Jenkins Pipeline

Learn how to add GitHub webhooks to Jenkins pipelines to trigger the build when a developer commits code to the master branch.

Sachin Slathia user avatar by
Sachin Slathia
·
Oct. 27, 18 · Tutorial
Like (15)
Save
Tweet
Share
284.88K Views

Join the DZone community and get the full member experience.

Join For Free

Have you ever tried adding GitHub webhook in Jenkins? In this blog, I will be demonstrating the easiest way to add a webhook in your pipeline.

First, 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 through a simple event-notification via HTTP POST.

GitHub webhooks in Jenkins are used to trigger the build whenever a developer commits something to the master branch.

Let’s see how to add build a webhook in GitHub and then add this webhook in Jenkins.

  1. Go to your project repository.
  2. Go to "settings" in the right corner.
  3. Click on "webhooks."
  4. Click "Add webhooks."
  5. Write the Payload URL as

https://228b9f82.ngrok.io/github-webhook/

2

Here, Payload URL is the URL where our Jenkins is running add github-webhook to tell GitHub that it is a webhook.

  • Content type: What kind of data we want in our webhook. I have selected JSON data.
  • 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 you diagnose problems with your SSL certificate installation. You can verify the SSL certificate on your web server to make sure it is correctly installed, valid, trusted and doesn’t give any errors to any of your users.

Which events would you like to trigger this webhook?

  1. Just the push event: Only send data when someone pushed into my repository.
  2. Send me everything: If there is any pull or push event in our repository we will get notified.
  3. Let me select individual events: We can configure for what events we want our data.

Click Create and a webhook will be created.

Untitled

Here https://228b9f82.ngrok.io/ is the port or IP where my Jenkins is running.

Here is a problem you have to take care of if you 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 you want to make your  localhost:8080 expose to the internet then we can use tool

Write GitHub-webhook to the ngrok tool refer to this link.

Now let’s see how to use this webhook in Jenkins.

  1. Go to Manage Jenkins -> Configure System
  2. Scroll down and you will find the GitHub Pull Requests checkbox. In the Published Jenkins URL, add the repository link
  3. Click on "Save."

Jenkins pipeline

Now go to the Jenkins pipeline and select "GitHub hook trigger for GITScm polling."

Jenkins pipeline

In this way, we can add a webhook to our job and ensure that everytime a developer commits a code to GitHub, our build will be triggered.

I hope this blog was helpful in adding GitHub webhooks in Jenkins.

Webhook Jenkins (software) GitHub Pipeline (software)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Orchestration Pattern: Managing Distributed Transactions
  • How Agile Architecture Spikes Are Used in Shift-Left BDD
  • How To Build a Spring Boot GraalVM Image
  • Best Practices for Writing Clean and Maintainable Code

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: