DEV Community

Cover image for Let GitHub and Jenkins Talk β€” Webhooks Make It Happen
Krisha Arya
Krisha Arya

Posted on

Let GitHub and Jenkins Talk β€” Webhooks Make It Happen

Hey Devs πŸ‘‹ Krisha here!

In this article, we'll explore how to integrate GitHub Webhooks with Jenkins, even when Jenkins is running locally.
We'll use Ngrok to expose our local Jenkins server to the internet β€” allowing GitHub to notify Jenkins about repo changes automatically.

Let’s get started πŸš€


✨ What is a Webhook?

A Webhook is a way for one application (like GitHub) to notify another (like Jenkins) when an event occurs β€” in real time.

β€œIt’s like GitHub sending a push notification to Jenkins saying β€˜Hey, new code was pushed!’”


πŸ› οΈ The Problem

When Jenkins runs locally (on localhost:8080), GitHub can't reach it β€” because it’s not publicly accessible.

βœ… The Solution β†’ Use Ngrok

Ngrok creates a secure public URL and forwards traffic to your local machine.
This makes it possible for GitHub to reach Jenkins even if it's running on your laptop.


πŸš€ Step-by-Step Guide

1️⃣ Install Ngrok

If you don’t have Ngrok installed yet:

sudo apt install snapd
sudo snap install ngrok
Enter fullscreen mode Exit fullscreen mode

Or download it from ngrok.com


2️⃣ Expose Jenkins (usually on port 8080)

ngrok http 8080
Enter fullscreen mode Exit fullscreen mode

You’ll get output like:

Forwarding   https://abcd1234.ngrok.io -> http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

βœ… Copy the HTTPS link β€” you’ll need it soon.


3️⃣ Configure GitHub Webhook

  1. Go to GitHub Repo β†’ Settings β†’ Webhooks β†’ Add webhook
  2. Set these fields:
Field Value
Payload URL https://abcd1234.ngrok.io/github-webhook/
(replace with your ngrok URL)
Content type application/json βœ…
Secret (Leave empty β€” optional)
SSL verification Enabled βœ…
  1. Select β€˜Just the push event’
  2. Click Save

4️⃣ Configure Jenkins GitHub Plugins

In Jenkins:

  • Go to Manage Jenkins β†’ Manage Plugins β†’ Installed
  • Ensure GitHub plugin and GitHub Integration Plugin are installed βœ…

5️⃣ Configure Jenkins Job (Pipeline)

  1. Open your Jenkins job β†’ Click Configure
  2. Scroll to Build Triggers
  3. Check βœ… GitHub hook trigger for GITScm polling

⚠️ Troubleshooting Common 403 Error (Invalid HTTP Response)

If GitHub webhook says Last delivery was not successful (403 Forbidden) β€” here’s the fix:

βœ… Checklist

Task Status
GitHub hook trigger enabled in Jenkins βœ…
CSRF β†’ "Enable proxy compatibility" checked βœ…
Webhook URL ends with /github-webhook/ βœ…
Ngrok tunnel is active on port 8080 βœ…
Jenkins restarted (optional) βœ…

Steps to Fix:

1️⃣ Allow anonymous POST (disable CSRF for hooks)
Manage Jenkins β†’ Configure Global Security
➑️ Under CSRF Protection, enable "Enable proxy compatibility"

2️⃣ Ensure correct webhook URL
Your Payload URL should end with /github-webhook/
(not just root ngrok URL)

3️⃣ Restart Jenkins
(Optional, but clears stale settings)

sudo systemctl restart jenkins
Enter fullscreen mode Exit fullscreen mode

4️⃣ Re-test webhook
In GitHub β†’ Webhook β†’ Click "Redeliver"
You should see HTTP 200 OK βœ…


⚑ Important Tips

  • Ngrok URL changes every time you restart ngrok
    β†’ Update the webhook URL in GitHub accordingly

  • Want a fixed Ngrok URL?
    Consider Ngrok paid plan with reserved subdomains


πŸ“Š How Does This Flow Work?

Here’s the data flow summary:

GitHub push β†’ calls Webhook URL (ngrok) β†’ forwards to Jenkins β†’ Jenkins triggers Pipeline
Enter fullscreen mode Exit fullscreen mode

πŸ“ Conclusion

Using Ngrok + GitHub Webhooks + Jenkins gives you a powerful local CI/CD pipeline β€” even while developing on your laptop.

Now, every time you push to GitHub β†’ Jenkins can auto-trigger builds, run tests, and more πŸš€


Top comments (0)