Connecting GitHub and Jenkins
By: zigmoid
Posted on: 04/25/2025
๐ก What Youโll Need Before You Start
- A GitHub repo with something Jenkins can build.
- Jenkins up and running (local or hosted).
- Git plugin + GitHub plugin installed in Jenkins.
- GitHub Personal Access Token (PAT) or SSH key for auth.
- Optionally: Webhook setup so Jenkins gets notified on code pushes (CI magic!).
๐ Step 1: Install Git & GitHub Plugins in Jenkins
Head to:
- Manage Jenkins โ Manage Plugins โ Available
- Search and install:
- Git Plugin
- GitHub Plugin
- (Optional but useful) GitHub Branch Source Plugin
- Restart Jenkins if it asks nicely
๐ Step 2: Create GitHub Credentials for Jenkins
You have two good options here:
Option 1: Use HTTPS + PAT (Recommended)
- Go to GitHub โ Settings โ Developer settings โ Personal Access Tokens
- Generate a token with:
repo
accessadmin:repo_hook
(if you want Jenkins to manage webhooks)
Option 2: Use SSH Key (Only if youโre anti-PAT)
- Generate an SSH key on your Jenkins server: bashCopyEdit
ssh-keygen -t rsa -b 4096 -C "jenkins@yourdomain.com"
- Add the public key to your GitHub repo under Deploy Keys
- Add the private key to Jenkins:
- Manage Jenkins โ Credentials โ Add a new SSH Username with private key
โ๏ธ Step 3: Set Up Your Jenkins Job to Use GitHub
- Create a new job โ Select Pipeline or Freestyle
- In the Source Code Management section:
- Select Git
- Paste your repo URL (
https://github.com/username/repo.git
) - Add your credentials from earlier
- (Optional but very cool): If using a Jenkinsfile, select โPipeline script from SCMโ and point to your Jenkinsfile in the repo.
๐ฃ Step 4: Enable GitHub Webhooks (Push-Triggered Builds)
So Jenkins doesnโt sit there twiddling its thumbs.
Option 1: Auto-Webhooks via GitHub Plugin (if you gave Jenkins PAT with admin access)
- Check GitHub hook trigger for GITScm polling in your job’s build triggers
Option 2: Manual Webhook (if youโre DIY-ing it)
- Go to your GitHub repo โ Settings โ Webhooks โ Add webhook
- Payload URL: perlCopyEdit
http://<jenkins-server>/github-webhook/
or if Jenkins is running locally and GitHub canโt reach it, use ngrok or a reverse proxy. - Content type:
application/json
- Events: Choose Just the push event
- Save it
๐งช Step 5: Test It!
- Commit and push something to your GitHub repo.
- Jenkins should automatically detect the change and kick off a build.
- If not:
- Check webhook delivery logs on GitHub
- Make sure your Jenkins server is publicly accessible
- Check job logs for auth errors
๐ง Bonus: Use Multibranch Pipelines
If you’re working with multiple branches, check out Multibranch Pipeline Jobs:
- They auto-detect branches with a
Jenkinsfile
- Jenkins creates separate jobs for each branch
- Supports PR builds too
Set it up under New Item โ Multibranch Pipeline
๐ Wrap-Up
Now GitHub and Jenkins are linked like Batman and Robin, youโve unlocked:
- Auto builds on every push
- Super clean CI/CD pipeline tied to your actual code
- Version-controlled Jenkinsfile workflows
No more manual triggers. No more stale builds. Just sweet, sweet automation.