Connecting GitHub and Jenkins

By: zigmoid
Posted on: 04/25/2025

๐Ÿ’ก What Youโ€™ll Need Before You Start

  1. A GitHub repo with something Jenkins can build.
  2. Jenkins up and running (local or hosted).
  3. Git plugin + GitHub plugin installed in Jenkins.
  4. GitHub Personal Access Token (PAT) or SSH key for auth.
  5. 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)

  1. Go to GitHub โ†’ Settings โ†’ Developer settings โ†’ Personal Access Tokens
  2. Generate a token with:
    • repo access
    • admin:repo_hook (if you want Jenkins to manage webhooks)

Option 2: Use SSH Key (Only if youโ€™re anti-PAT)

  1. Generate an SSH key on your Jenkins server: bashCopyEditssh-keygen -t rsa -b 4096 -C "jenkins@yourdomain.com"
  2. Add the public key to your GitHub repo under Deploy Keys
  3. 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

  1. Create a new job โ†’ Select Pipeline or Freestyle
  2. In the Source Code Management section:
    • Select Git
    • Paste your repo URL (https://github.com/username/repo.git)
    • Add your credentials from earlier
  3. (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)

  1. Go to your GitHub repo โ†’ Settings โ†’ Webhooks โ†’ Add webhook
  2. Payload URL: perlCopyEdithttp://<jenkins-server>/github-webhook/ or if Jenkins is running locally and GitHub canโ€™t reach it, use ngrok or a reverse proxy.
  3. Content type: application/json
  4. Events: Choose Just the push event
  5. Save it

๐Ÿงช Step 5: Test It!

  1. Commit and push something to your GitHub repo.
  2. Jenkins should automatically detect the change and kick off a build.
  3. 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.