Skip to main content

Command Palette

Search for a command to run...

Automate Jenkins Build with GitHub Webhook on Amazon Linux 2

Published
2 min readView as Markdown
Automate Jenkins Build with GitHub Webhook on Amazon Linux 2

🎯 Project Objective

Automate your Jenkins CI pipeline using GitHub webhooks so that any git push to the repository triggers a Jenkins job — removing manual build triggers.


🧰 Tools Used

  • Amazon EC2 (Amazon Linux 2)

  • Jenkins

  • GitHub

  • Maven (Optional, if you're building a Java project)

  • Ngrok (To expose local Jenkins to GitHub Webhooks)


🚀 Step-by-Step Guide

1️⃣ Ensure Jenkins is Running

  • Jenkins should be accessible on your EC2 instance via http://<public-ip>:8080

2️⃣ Install GitHub Plugin in Jenkins

  • Go to: Manage Jenkins → Plugin Manager → Available

  • Search & install: GitHub Integration Plugin, GitHub Branch Source Plugin


3️⃣ Set Up a Jenkins Job for Your GitHub Repo

  • New Item → Freestyle Project

  • Under Source Code Management, choose Git

  • Add your GitHub repo URL

  • Use credentials if private repo

  • In Build Triggers, check: ✅ GitHub hook trigger for GITScm polling


4️⃣ Expose Jenkins to the Internet (Temporary) Using Ngrok

Jenkins is running on EC2, but GitHub needs a public HTTPS URL. Use ngrok.

  • Download Ngrok on your local machine

  • Expose Jenkins:

      ngrok http 8080
    
  • Copy the HTTPS URL like https://abcd1234.ngrok.io


5️⃣ Update GitHub Webhook

  • Go to your GitHub Repo → Settings → Webhooks

  • Click Add webhook

    • Payload URL: https://abcd1234.ngrok.io/github-webhook/

    • Content type: application/json

    • Events: ✅ Just the push event

    • Click Add webhook


6️⃣ Test the Webhook

  • Make a small change in your GitHub repo (e.g., edit README)

  • Push it:

      git add .
      git commit -m "Trigger Jenkins build"
      git push
    
  • Go to Jenkins — you should see the job running automatically! 🚀


Expected Outcome

  • Jenkins job is triggered automatically every time code is pushed to the GitHub repo.

  • No manual triggering required anymore.

More from this blog

D

DevOps Dost

9 posts