0
0
Jenkinsdevops~10 mins

Build status badges in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Build status badges
Start Jenkins Job
Job Runs Build
Build Passes or Fails
Update Badge Status
Badge URL Shows Status
Users See Badge on README or Dashboard
The Jenkins job runs a build, updates the badge status based on success or failure, and the badge URL reflects this status for users.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        sh 'make build'
      }
    }
  }
  post {
    success {
      script {
        currentBuild.description = "![Build Status](https://img.shields.io/badge/build-passing-brightgreen)"
      }
    }
    failure {
      script {
        currentBuild.description = "![Build Status](https://img.shields.io/badge/build-failing-red)"
      }
    }
  }
}
This Jenkins pipeline runs a build and sets a badge URL in the build description showing pass or fail status.
Process Table
StepActionBuild ResultBadge URLUser View
1Start Jenkins JobN/AN/ANo badge yet
2Run 'make build'RunningN/ANo badge yet
3Build completes successfullySuccesshttps://img.shields.io/badge/build-passing-brightgreenGreen passing badge shown
4Set build description with passing badgeSuccesshttps://img.shields.io/badge/build-passing-brightgreenGreen passing badge shown
5User views README or dashboardSuccesshttps://img.shields.io/badge/build-passing-brightgreenGreen passing badge visible
6If build fails insteadFailurehttps://img.shields.io/badge/build-failing-redRed failing badge shown
7Set build description with failing badgeFailurehttps://img.shields.io/badge/build-failing-redRed failing badge shown
8User views README or dashboardFailurehttps://img.shields.io/badge/build-failing-redRed failing badge visible
💡 Build finishes with success or failure, badge URL updated accordingly, user sees badge status.
Status Tracker
VariableStartAfter Build SuccessAfter Build Failure
currentBuild.descriptionnull![Build Status](https://img.shields.io/badge/build-passing-brightgreen)![Build Status](https://img.shields.io/badge/build-failing-red)
Key Moments - 2 Insights
Why does the badge URL change after the build finishes?
Because the Jenkins pipeline updates currentBuild.description in the post section depending on success or failure, as shown in execution_table rows 4 and 7.
Can the badge show status before the build finishes?
No, the badge URL is set only after the build completes, so before that it is not available, as seen in execution_table rows 1 and 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the build result and badge URL?
ABuild Result: Running, Badge URL: N/A
BBuild Result: Success, Badge URL: https://img.shields.io/badge/build-passing-brightgreen
CBuild Result: Failure, Badge URL: https://img.shields.io/badge/build-failing-red
DBuild Result: Success, Badge URL: N/A
💡 Hint
Check row 3 in execution_table for build result and badge URL after build success.
At which step does the user first see the badge on the dashboard?
AStep 2
BStep 4
CStep 5
DStep 1
💡 Hint
Look at execution_table rows where User View column shows badge visibility.
If the build fails, what will currentBuild.description be set to?
A![Build Status](https://img.shields.io/badge/build-failing-red)
B![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
Cnull
DNo change
💡 Hint
Check variable_tracker for currentBuild.description after build failure.
Concept Snapshot
Build status badges show if a Jenkins build passed or failed.
Use pipeline post blocks to set badge URLs.
Badge URLs use services like shields.io.
Users see badges on README or dashboards.
Badge updates only after build finishes.
Full Transcript
This visual execution shows how Jenkins builds update a build status badge. The pipeline runs a build command. After the build finishes, the pipeline sets the build description to a badge URL. If the build succeeds, the badge is green and says passing. If it fails, the badge is red and says failing. Users see the badge on project pages or dashboards. The badge updates only after the build completes, never before. Variables like currentBuild.description hold the badge URL and change after build success or failure.