Consider this Jenkins pipeline snippet:
options {
timeout(time: 1, unit: 'MINUTES')
}
stage('Example') {
steps {
sh 'sleep 90'
}
}What is the expected outcome when this pipeline runs?
options {
timeout(time: 1, unit: 'MINUTES')
}
stage('Example') {
steps {
sh 'sleep 90'
}
}Think about what the timeout option does in Jenkins pipelines.
The timeout option stops the stage if it runs longer than the specified time. Here, the stage runs a 90-second sleep but the timeout is 1 minute, so Jenkins aborts the stage with a timeout error.
Given this Jenkins pipeline snippet:
options {
retry(3)
}
stage('Build') {
steps {
sh 'exit 1'
}
}What will Jenkins do when the shell command fails?
options {
retry(3)
}
stage('Build') {
steps {
sh 'exit 1'
}
}Consider what the retry option number means.
The retry(3) option tells Jenkins to try the stage up to 3 times if it fails. If all retries fail, the pipeline fails.
Which options block correctly sets a retry count of 2 and a timeout of 5 minutes for a Jenkins pipeline stage?
Remember the syntax for options directives in Jenkins pipelines.
The correct syntax uses separate directives inside the options block. Option A correctly sets retry(2) and timeout(time: 5, unit: 'MINUTES'). Other options have syntax errors or invalid usage.
Given this Jenkins pipeline snippet:
options {
retry(3)
}
stage('Test') {
steps {
script {
try {
sh 'exit 1'
} catch (e) {
echo 'Caught error'
}
}
}
}Why does Jenkins not retry the stage even though retry(3) is set?
options {
retry(3)
}
stage('Test') {
steps {
script {
try {
sh 'exit 1'
} catch (e) {
echo 'Caught error'
}
}
}
}Think about how Jenkins detects failures to retry.
Jenkins retries a stage only if it fails. Here, the failure is caught by the try-catch block, so Jenkins sees the stage as successful and does not retry.
You want to run a test stage that might fail sometimes and could hang. You want to retry it up to 2 times and also stop it if it runs longer than 3 minutes each try.
Which Jenkins pipeline options block achieves this correctly?
Check the correct syntax for combining options in Jenkins pipelines.
Option C correctly sets retry and timeout as separate directives inside the options block. Option C uses invalid nested syntax. Option C and D have incorrect syntax for timeout.