Skip to content
DBDeependra Bhatta~/notes
CI/CD#cloud · #github · #jenkins · #technology · #web-hooks

Github Hooks in Jenkins

🚀 Step 1: Install Required Jenkins Plugins Go to Jenkins Dashboard → Manage Jenkins → Manage Plugins. GitHub Integration GitHub Plugin Pipeline: GitHub (if not installed) Install and Restart…

· updated · 3 min read
ON THIS PAGE

🚀 Step 1: Install Required Jenkins Plugins

  1. Go to Jenkins Dashboard → Manage Jenkins → Manage Plugins.
  2. Under the Available tab, search for:
    • GitHub Integration
    • GitHub Plugin
    • Pipeline: GitHub (if not installed)
  3. Install and Restart Jenkins.

🚀 Step 2: Configure GitHub Webhook in Jenkins

A. Configure Jenkins for GitHub Webhooks

  1. Go to Manage Jenkins → Configure System.
  2. Under GitHub, add a GitHub Server:
    • Name: GitHub (or any name)
    • API URL: https://api.github.com
    • Credentials: Click Add → Jenkins:
      • Kind: Secret text
      • Secret: GitHub Personal Access Token
      • ID: github-token (or any ID)
    • Click Test Connection (should say “Credentials verified”).
    • ✅ Manage hooks (must be checked).

Github Hooks in Jenkins screenshot 1

Save.

B. Update Jenkins Pipeline to Use GitHub Webhook

  1. Open your Jenkinsfile (or pipeline script).
GRVGroovy
pipeline {
    agent none
 
    triggers {
        // Trigger on push to 'develop' branch
        githubPush()
    }
 
    environment {
        mydockerimage = "harbor.registry.local/jenkins/mylocalimage"
    }
 
    stages {
        // Your existing stages...
    }
}
  1. Commit & Push to GitHub.

Now it’s time to setup web hook in github

  • Currently i am using vagrant machine and i have tried a lot to expose it port publically but i was unable to so to trigger the web hook i have used ngrok.
  • To setup ngrok i have have installed and setup with github link.

Install ngork

  • After installation signup and add the authentication key in the machine.
  • After that you can run this command “ngrok http 8080” this will provide a url like this “https://2ca59e943d83.ngrok-free.app/github-webhook/” in current screen.
  • To run in background i have created a script and it will run and print the url in screen.
SHBash
#!/bin/bash
 
PORT=8080
LOGFILE="ngrok.log"
 
# Kill any existing ngrok process on this port (optional)
pkill -f "ngrok http $PORT"
 
# Start ngrok in background and save logs
nohup ngrok http $PORT > $LOGFILE 2>&1 &
 
# Wait for ngrok to initialize
sleep 5
 
# Fetch the public HTTPS URL
NGROK_URL=$(curl -s http://localhost:4040/api/tunnels \
  | grep -o 'https://[a-zA-Z0-9.-]*.ngrok-free.app' | head -n 1)
 
if [[ -n "$NGROK_URL" ]]; then
  echo "Your Jenkins webhook URL is:"
  echo "$NGROK_URL/github-webhook/"
  echo ""
  echo "Use this URL in your GitHub webhook settings."
else
  echo "Failed to get ngrok URL. Check logs in $LOGFILE"
fi

Github Hooks in Jenkins screenshot 2

  • After getting this url paste it in the

Github Hooks in Jenkins screenshot 3

  • In payload url paste the link and content-type application/x and add this.
  • Now let’s configure jenkins to detect this

Github Hooks in Jenkins screenshot 4

Github Hooks in Jenkins screenshot 5

Github Hooks in Jenkins screenshot 6

  • After setting all these now if you push the code to github it will automatically trigger the pipeline.
  • Distributed Build Example in Jenkins

    Creating 2 VMs to know the concept of multistage distributed builds. Setting up Node in Jenkins master Setting label for Jenkins master Example 1: So first let’s run a simple pipeline in this node…

  • Maven, Tomcat and Jenkins simple project

    In this project we are creating a maven project and deploying it with tomcat. We are building and deploying manually to see the manual steps of deploying a war file. After that we will be deploying…

  • GITHUB Actions

    From Zero to Deploy: Building a MERN Stack CI/CD Pipeline with GitHub Actions Continuous Integration (CI) and Continuous Deployment (CD) have become essential pillars of modern software development…