Bird
Raised Fist0
Jenkinsdevops~20 mins

currentBuild variables in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
currentBuild Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of accessing currentBuild.result before any stage runs?

In a Jenkins pipeline, what will be the value of currentBuild.result before any build stage executes?

Jenkins
pipeline {
  agent any
  stages {
    stage('Check') {
      steps {
        script {
          echo "Result is: ${currentBuild.result}"
        }
      }
    }
  }
}
A"UNSTABLE"
B"SUCCESS"
C"FAILURE"
Dnull
Attempts:
2 left
💡 Hint

Think about the default state of the build result before any steps run.

🧠 Conceptual
intermediate
1:30remaining
Which currentBuild variable holds the build number as an integer?

In Jenkins pipeline scripts, which currentBuild variable contains the build number as an integer (not a string)?

AcurrentBuild.displayName
BcurrentBuild.number
CcurrentBuild.id
DcurrentBuild.buildNumber
Attempts:
2 left
💡 Hint

Check the official Jenkins documentation for currentBuild properties.

❓ Troubleshoot
advanced
2:00remaining
Why does currentBuild.duration sometimes show 0 during pipeline execution?

In a Jenkins pipeline, you notice currentBuild.duration is 0 even after some stages have completed. What is the most likely reason?

A<code>currentBuild.duration</code> shows 0 if the build is running on a slave node.
B<code>currentBuild.duration</code> resets to 0 after each stage.
C<code>currentBuild.duration</code> only updates after the build finishes.
D<code>currentBuild.duration</code> requires a plugin to work.
Attempts:
2 left
💡 Hint

Think about when Jenkins calculates the total build duration.

✅ Best Practice
advanced
1:30remaining
Which currentBuild property should you check to detect if a build was aborted?

In a Jenkins pipeline, which currentBuild property value indicates the build was aborted by a user?

A<code>currentBuild.result == 'ABORTED'</code>
B<code>currentBuild.status == 'ABORTED'</code>
C<code>currentBuild.aborted == true</code>
D<code>currentBuild.isAborted()</code>
Attempts:
2 left
💡 Hint

Check the standard string values Jenkins uses for build results.

🔀 Workflow
expert
2:30remaining
Order the steps to correctly set and check currentBuild.description in a scripted pipeline

Arrange the following code lines in the correct order to set a build description and then check it in a Jenkins scripted pipeline.

A1,2,3,4
B2,1,3,4
C1,3,2,4
D2,3,1,4
Attempts:
2 left
💡 Hint

Think about setting a value before checking it.

Practice

(1/5)
1. What does the currentBuild.number variable represent in a Jenkins Pipeline?
easy
A. The number of failed tests in the build
B. The unique build number of the current running job
C. The number of parallel stages in the pipeline
D. The total number of builds ever run on Jenkins

Solution

  1. Step 1: Understand the role of currentBuild

    The currentBuild variable holds information about the current Jenkins job execution.
  2. Step 2: Identify what number means

    The number property specifically gives the unique build number assigned to this run.
  3. Final Answer:

    The unique build number of the current running job -> Option B
  4. Quick Check:

    currentBuild.number = build number [OK]
Hint: Remember: currentBuild.number is the build's unique ID [OK]
Common Mistakes:
  • Confusing build number with total builds
  • Thinking it counts test failures
  • Mixing it with stage counts
2. Which of the following is the correct way to access the current build's result status in a Jenkins Pipeline script?
easy
A. currentBuild.result
B. currentBuild.status
C. currentBuild.state
D. currentBuild.outcome

Solution

  1. Step 1: Recall the property for build result

    The Jenkins currentBuild object uses result to store the build status like SUCCESS or FAILURE.
  2. Step 2: Verify other options

    status, state, and outcome are not valid properties for currentBuild.
  3. Final Answer:

    currentBuild.result -> Option A
  4. Quick Check:

    Build status = currentBuild.result [OK]
Hint: Use currentBuild.result for build status, not status or state [OK]
Common Mistakes:
  • Using currentBuild.status which is undefined
  • Confusing result with outcome
  • Trying to access non-existent properties
3. Given this Jenkins Pipeline snippet:
echo "Build number: ${currentBuild.number}"
echo "Build status: ${currentBuild.result}"

If the build number is 42 and the build just finished successfully, what will be the output?
medium
A. Build number: 42 Build status: SUCCESS
B. Build number: 42 Build status: null
C. Build number: null Build status: SUCCESS
D. Build number: 0 Build status: FAILURE

Solution

  1. Step 1: Understand variable values after build

    After a successful build, currentBuild.number is the build number (42), and currentBuild.result is "SUCCESS".
  2. Step 2: Substitute variables in echo statements

    Replacing variables gives:
    Build number: 42
    Build status: SUCCESS
  3. Final Answer:

    Build number: 42 Build status: SUCCESS -> Option A
  4. Quick Check:

    Number=42, Result=SUCCESS [OK]
Hint: After success, currentBuild.result = SUCCESS, number = build ID [OK]
Common Mistakes:
  • Expecting result to be null before build ends
  • Confusing build number with zero
  • Assuming result is FAILURE by default
4. You wrote this Jenkins Pipeline snippet:
if (currentBuild.status == 'SUCCESS') {
  echo 'Build succeeded'
} else {
  echo 'Build failed'
}

But it always prints 'Build failed' even when the build succeeds. What is the issue?
medium
A. The string comparison should use == instead of =
B. The if statement needs parentheses around the condition
C. The echo command is incorrect syntax
D. The property should be currentBuild.result, not currentBuild.status

Solution

  1. Step 1: Identify the incorrect property usage

    The currentBuild object does not have a status property; the correct property for build result is result.
  2. Step 2: Understand why the condition fails

    Since currentBuild.status is undefined, the condition never matches 'SUCCESS', so it always goes to else.
  3. Final Answer:

    The property should be currentBuild.result, not currentBuild.status -> Option D
  4. Quick Check:

    Use currentBuild.result for status check [OK]
Hint: Use currentBuild.result, not currentBuild.status, for build status [OK]
Common Mistakes:
  • Using currentBuild.status instead of currentBuild.result
  • Confusing assignment (=) with comparison (==)
  • Incorrect echo syntax in Jenkinsfile
5. In a Jenkins Pipeline, you want to set the display name of the current build to include the build number and status, like "Build #42 - SUCCESS". Which snippet correctly does this?
hard
A. currentBuild.displayName = "Build #${build.number} - ${build.result}"
B. currentBuild.name = "Build #${currentBuild.number} - ${currentBuild.status}"
C. currentBuild.displayName = "Build #${currentBuild.number} - ${currentBuild.result}"
D. currentBuild.setDisplayName("Build #${currentBuild.number} - ${currentBuild.result}")

Solution

  1. Step 1: Identify the correct property to set display name

    The property to set the build's display name is currentBuild.displayName.
  2. Step 2: Use correct variable names and syntax

    Use currentBuild.number and currentBuild.result inside the string with Groovy string interpolation.
  3. Final Answer:

    currentBuild.displayName = "Build #${currentBuild.number} - ${currentBuild.result}" -> Option C
  4. Quick Check:

    Set displayName with currentBuild.displayName and correct variables [OK]
Hint: Set displayName with currentBuild.displayName and correct variables [OK]
Common Mistakes:
  • Using currentBuild.name instead of displayName
  • Using undefined variable 'build'
  • Trying to call setDisplayName() which doesn't exist
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