💡 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:
repoaccessadmin: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.