In a Jenkins pipeline, what will be the value of currentBuild.result before any build stage executes?
pipeline {
agent any
stages {
stage('Check') {
steps {
script {
echo "Result is: ${currentBuild.result}"
}
}
}
}
}Think about the default state of the build result before any steps run.
Before any stage runs, currentBuild.result is null because Jenkins has not yet set a result. It only gets a value like SUCCESS or FAILURE after stages execute.
In Jenkins pipeline scripts, which currentBuild variable contains the build number as an integer (not a string)?
Check the official Jenkins documentation for currentBuild properties.
currentBuild.number holds the build number as an integer. Other properties like id or displayName are strings.
In a Jenkins pipeline, you notice currentBuild.duration is 0 even after some stages have completed. What is the most likely reason?
Think about when Jenkins calculates the total build duration.
currentBuild.duration is only updated once the build finishes. During execution, it remains 0.
In a Jenkins pipeline, which currentBuild property value indicates the build was aborted by a user?
Check the standard string values Jenkins uses for build results.
The currentBuild.result property holds the build status as a string. When a build is aborted, it is set to 'ABORTED'. Other options are invalid or do not exist.
Arrange the following code lines in the correct order to set a build description and then check it in a Jenkins scripted pipeline.
Think about setting a value before checking it.
You must first assign currentBuild.description before you can check its value. So the correct order is setting it (1), then starting the if block (2), echoing (3), and closing the block (4).