How to Send Jenkins Build Status to GitHub Commits and PRs?

How to Send Jenkins Build Status to GitHub Commits and PRs?

To improve visibility into CI/CD workflows, we integrated Jenkins with GitHub to send live pipeline status updates directly to commits and pull requests. Each stage in the Jenkins pipeline (like Build, Scan, Dockerize, and Deploy) now reflects clearly in GitHub’s Checks tab. This integration helps developers quickly see what passed or failed—without leaving GitHub. We used GitHub’s status API and Jenkins curl scripts to make it seamless.

✅ Prerequisites

  1. GitHub Repo
  2. Jenkins Server
  3. Jenkins must have: GitHub plugin, GitHub Integration plugin, Pipeline plugin, GitHub Branch Source plugin.
  4. A GitHub Personal Access Token (PAT) with repo:status permission.

Step 1: Generate GitHub Personal Access Token (PAT)

  1. Go to GitHub → Settings → Developer Settings → Personal Access Tokens (Fine-grained or Classic).

Article content


Article content


Article content


Article content

Generate and Save the token securely.

Article content

Step 2: Add GitHub Token to Jenkins Credentials

  1. Go to Jenkins → Manage JenkinsCredentials

Article content

2. Choose:

  • Domain: (Global)
  • Kind: Secret text
  • ID: github-pat
  • Secret: (Paste your GitHub PAT)


Article content


Article content

Similar way add Secrets for Github User name and Password.

  • Kind: Username with password
  • Username: your GitHub username (abhishekvarale)
  • Password: your GitHub Personal Access Token (PAT) with repo or repo:status access
  • ID: github-access (or any ID you’ll recognize)
  • Click Save


Article content

Step 3: Create Dummy Jenkins Pipeline (Declarative)

  1. Go to Jenkins → New Item → Pipeline → dummy-github-integration (Give your Project name)

Article content

  1. Use this sample Jenkinsfile with dummy stages and status reporting:

pipeline {

agent any

environment {

REPO = "abhishekvarale/FTPT1998"

BRANCH = "main"

CLONE_DIR = "source"

}

stages {

stage('Clone') {

steps {

dir("${CLONE_DIR}") {

git url: "https://github.com/${REPO}.git", branch: "${BRANCH}"

script {

env.COMMIT_SHA = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()

echo "Cloned Commit: ${env.COMMIT_SHA}"

}

}

script {

sendGitHubStatus("pending", "Pipeline started...", "Jenkins / Clone")

}

}

}

stage('Build') {

steps {

script {

sendGitHubStatus("pending", "Building app...", "Jenkins / Build")

}

echo '🏗️ Dummy build step'

}

post {

success {

script {

sendGitHubStatus("success", "Build succeeded", "Jenkins / Build")

}

}

failure {

script {

sendGitHubStatus("failure", "Build failed", "Jenkins / Build")

}

}

}

}

stage('Scan') {

steps {

script {

sendGitHubStatus("pending", "Running scan...", "Jenkins / Scan")

}

echo '🔍 Dummy scan step'

}

post {

success {

script {

sendGitHubStatus("success", "Scan passed", "Jenkins / Scan")

}

}

failure {

script {

sendGitHubStatus("failure", "Scan failed", "Jenkins / Scan")

}

}

}

}

stage('Dockerize') {

steps {

script {

sendGitHubStatus("pending", "Building Docker image...", "Jenkins / Dockerize")

}

echo '🐳 Dummy docker step'

}

post {

success {

script {

sendGitHubStatus("success", "Docker build done", "Jenkins / Dockerize")

}

}

failure {

script {

sendGitHubStatus("failure", "Docker step failed", "Jenkins / Dockerize")

}

}

}

}

stage('Deploy') {

steps {

script {

sendGitHubStatus("pending", "Deploying...", "Jenkins / Deploy")

}

echo '🚀 Dummy deploy step'

}

post {

success {

script {

sendGitHubStatus("success", "Deployed successfully", "Jenkins / Deploy")

}

}

failure {

script {

sendGitHubStatus("failure", "Deployment failed", "Jenkins / Deploy")

}

}

}

}

}

post {

success {

script {

sendGitHubStatus("success", "Pipeline completed", "Jenkins / Full Pipeline")

}

}

failure {

script {

sendGitHubStatus("failure", "Pipeline failed", "Jenkins / Full Pipeline")

}

}

}

}

// ✅ Status updater function (adds clickable build link)

def sendGitHubStatus(String state, String description, String context) {

withCredentials([string(credentialsId: 'github-pat', variable: 'GITHUB_TOKEN')]) {

sh """

curl -s -X POST \

-H "Authorization: token \$GITHUB_TOKEN" \

-H "Accept: application/vnd.github.v3+json" \

https://api.github.com/repos/${env.REPO}/statuses/${env.COMMIT_SHA} \

-d '{

"state": "${state}",

"context": "${context}",

"description": "${description}",

"target_url": "${env.BUILD_URL}"

}'

"""

}

}

Add script and save it.

Note: Change your REPO URL accordingly.


Article content

Select Checkbox for Github Project and add github repo URL.


Article content

Also select checkbox for Github hook trigger for GITscm pooling.

Article content

Step 4: Configure Webhook in GitHub

  1. Go to your GitHub repo → Settings → Webhooks

Article content

Add new webhook:

  • Payload URL: http://your-jenkins-url/github-webhook/
  • Content type: application/json
  • Events: Just the push event (or pull request, optionally)

Article content

This lets Jenkins auto-trigger jobs on push/PR.

Step 5: Test It

  1. Push a commit or create a PR in your GitHub repo.

Article content

Jenkins should auto-trigger (if webhook works).you can check webhook Delivery history. settings>Webhooks>Recent Deliveries


Article content

After every run, Jenkins will update:

  • ✔️ Passed
  • ❌ Failed
  • ⏳ Pending

Article content

We got this status from jenkins on github UI.

Article content

  1. You’ll see Jenkins CI status on:

  • Commit history
  • Pull request checks
  • Merge validation

To view or add a comment, sign in

Others also viewed

Explore topics