Bird
Raised Fist0
Jenkinsdevops~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does a Jenkins build status badge typically indicate?
easy
A. Whether the build is passing or failing
B. The number of tests in the project
C. The size of the build artifact
D. The time taken to complete the build

Solution

  1. Step 1: Understand the purpose of build status badges

    Build status badges visually show the current state of a Jenkins job's build, mainly if it is passing or failing.
  2. Step 2: Identify what the badge communicates

    The badge does not show test counts, artifact size, or build time; it only shows build success or failure.
  3. Final Answer:

    Whether the build is passing or failing -> Option A
  4. Quick Check:

    Build status badge = Pass/Fail [OK]
Hint: Badges show pass or fail status only [OK]
Common Mistakes:
  • Confusing badge with test reports
  • Thinking badge shows build duration
  • Assuming badge shows artifact details
2. Which of the following is the correct format to get a Jenkins build status badge URL for a job named MyJob on http://jenkins.example.com?
easy
A. http://jenkins.example.com/MyJob/badge
B. http://jenkins.example.com/job/MyJob/badge/icon
C. http://jenkins.example.com/job/MyJob/build/badge
D. http://jenkins.example.com/job/MyJob/status/badge

Solution

  1. Step 1: Recall Jenkins badge URL pattern

    The standard Jenkins badge URL for a job is: http://[jenkins_url]/job/[job_name]/badge/icon.
  2. Step 2: Match the correct URL format

    http://jenkins.example.com/job/MyJob/badge/icon matches this pattern exactly for job MyJob.
  3. Final Answer:

    http://jenkins.example.com/job/MyJob/badge/icon -> Option B
  4. Quick Check:

    Badge URL = /job/JobName/badge/icon [OK]
Hint: Badge URL ends with /badge/icon [OK]
Common Mistakes:
  • Omitting /job/ in URL
  • Adding extra path segments like /build or /status
  • Using incorrect order of URL parts
3. Given the Jenkins badge URL http://jenkins.example.com/job/TestProject/badge/icon, what will the badge image show if the last build failed?
medium
A. A green badge with 'passing' text
B. A yellow badge with 'unstable' text
C. A gray badge with 'not built' text
D. A red badge with 'failing' text

Solution

  1. Step 1: Understand badge colors and meanings

    In Jenkins, a failed build shows a red badge labeled 'failing'.
  2. Step 2: Match badge color to build status

    Since the last build failed, the badge will be red with 'failing' text.
  3. Final Answer:

    A red badge with 'failing' text -> Option D
  4. Quick Check:

    Failed build = red 'failing' badge [OK]
Hint: Red badge means build failed [OK]
Common Mistakes:
  • Confusing red with green for success
  • Thinking yellow means failure
  • Assuming gray means failure
4. You added a build status badge URL to your README but the badge image shows 'not found'. What is the most likely cause?
medium
A. The Jenkins job name in the URL is incorrect
B. The Jenkins server is down
C. The badge URL is missing the /badge/icon suffix
D. The build is currently running

Solution

  1. Step 1: Check common reasons for 'not found' badge

    A 'not found' badge usually means the URL points to a non-existent resource.
  2. Step 2: Identify the most common URL mistake

    Incorrect job name in the URL causes Jenkins to return 404, showing 'not found' badge.
  3. Final Answer:

    The Jenkins job name in the URL is incorrect -> Option A
  4. Quick Check:

    Wrong job name = 'not found' badge [OK]
Hint: Check job name spelling in badge URL [OK]
Common Mistakes:
  • Assuming server down causes 'not found'
  • Forgetting /badge/icon suffix
  • Thinking running build causes 'not found'
5. You want to embed a Jenkins build status badge in your GitHub README.md file for a job named DeployApp on http://ci.example.com. Which markdown snippet correctly embeds the badge image linking to the Jenkins job page?
hard
A. [![Build Status](http://ci.example.com/job/DeployApp/)](http://ci.example.com/job/DeployApp/badge/icon)
B. [Build Status](http://ci.example.com/job/DeployApp/badge/icon)
C. [![Build Status](http://ci.example.com/job/DeployApp/badge/icon)](http://ci.example.com/job/DeployApp/)
D. ![Build Status](http://ci.example.com/job/DeployApp/badge/icon)

Solution

  1. Step 1: Understand markdown syntax for linked images

    Markdown syntax for an image with a link is: [![alt text](image URL)](link URL).
  2. Step 2: Apply correct URLs for Jenkins badge and job page

    The badge image URL is http://ci.example.com/job/DeployApp/badge/icon and the link should go to the job page http://ci.example.com/job/DeployApp/.
  3. Final Answer:

    [![Build Status](http://ci.example.com/job/DeployApp/badge/icon)](http://ci.example.com/job/DeployApp/) -> Option C
  4. Quick Check:

    Markdown linked image = [![alt](img)](link) [OK]
Hint: Use [![alt](badge URL)](job URL) for linked badge [OK]
Common Mistakes:
  • Using image without link
  • Linking badge URL instead of job URL
  • Incorrect markdown syntax for images
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard