0
0
Jenkinsdevops~20 mins

currentBuild variables in Jenkins - Practice Problems & Coding Challenges

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