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
Step 1: Generate GitHub Personal Access Token (PAT)
Generate and Save the token securely.
Step 2: Add GitHub Token to Jenkins Credentials
2. Choose:
Similar way add Secrets for Github User name and Password.
Step 3: Create Dummy Jenkins Pipeline (Declarative)
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" \
-d '{
"state": "${state}",
"context": "${context}",
"description": "${description}",
"target_url": "${env.BUILD_URL}"
}'
"""
}
}
Add script and save it.
Note: Change your REPO URL accordingly.
Select Checkbox for Github Project and add github repo URL.
Also select checkbox for Github hook trigger for GITscm pooling.
Step 4: Configure Webhook in GitHub
Add new webhook:
This lets Jenkins auto-trigger jobs on push/PR.
Step 5: Test It
Jenkins should auto-trigger (if webhook works).you can check webhook Delivery history. settings>Webhooks>Recent Deliveries
After every run, Jenkins will update:
We got this status from jenkins on github UI.