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
Or download it from ngrok.com
2οΈβ£ Expose Jenkins (usually on port 8080)
ngrok http 8080
Youβll get output like:
Forwarding https://abcd1234.ngrok.io -> http://localhost:8080
β Copy the HTTPS link β youβll need it soon.
3οΈβ£ Configure GitHub Webhook
- Go to GitHub Repo β Settings β Webhooks β Add webhook
- 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 β |
- Select βJust the push eventβ
- 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)
- Open your Jenkins job β Click Configure
- Scroll to Build Triggers
- 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
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 accordinglyWant 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
π 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)