0
0
Jenkinsdevops~20 mins

Build timeouts in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Build Timeout Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Jenkins Pipeline: Timeout Behavior
What will be the output if the following Jenkins pipeline script runs and the 'sleep' step exceeds the timeout duration?
Jenkins
pipeline {
  agent any
  stages {
    stage('Test Timeout') {
      steps {
        timeout(time: 1, unit: 'MINUTES') {
          sleep time: 90, unit: 'SECONDS'
          echo 'Completed sleep'
        }
      }
    }
  }
}
ABuild retries the sleep step automatically
BBuild completes successfully and prints 'Completed sleep'
CBuild is aborted silently without error message
DBuild fails with an error: Timeout has been exceeded
Attempts:
2 left
💡 Hint
Consider what happens when a step runs longer than the timeout block allows.
Configuration
intermediate
2:00remaining
Configuring Build Timeout in Jenkins Freestyle Job
Which configuration snippet correctly sets a build timeout of 10 minutes in a Jenkins freestyle job using the 'Build Timeout' plugin?
A
<hudson.plugins.build_timeout.BuildTimeoutWrapper>
  <timeoutMinutes>10</timeoutMinutes>
  <failBuild>false</failBuild>
</hudson.plugins.build_timeout.BuildTimeoutWrapper>
B
<hudson.plugins.build_timeout.BuildTimeoutWrapper>
  <timeoutMinutes>10</timeoutMinutes>
  <failBuild>true</failBuild>
</hudson.plugins.build_timeout.BuildTimeoutWrapper>
C
<hudson.plugins.build_timeout.BuildTimeoutWrapper>
  <timeoutSeconds>600</timeoutSeconds>
  <failBuild>true</failBuild>
</hudson.plugins.build_timeout.BuildTimeoutWrapper>
D
<hudson.plugins.build_timeout.BuildTimeoutWrapper>
  <timeoutMinutes>600</timeoutMinutes>
  <failBuild>false</failBuild>
</hudson.plugins.build_timeout.BuildTimeoutWrapper>
Attempts:
2 left
💡 Hint
Timeout is set in minutes, and failing the build on timeout is common.
Troubleshoot
advanced
2:00remaining
Diagnosing Timeout Not Triggering in Jenkins Pipeline
A Jenkins pipeline uses the 'timeout' step set to 5 minutes, but the build runs for 10 minutes without aborting. What is the most likely cause?
Jenkins
pipeline {
  agent any
  stages {
    stage('Long Task') {
      steps {
        timeout(time: 5, unit: 'MINUTES') {
          sh 'sleep 600'
        }
      }
    }
  }
}
AThe 'sleep' command inside 'sh' is not interruptible by Jenkins timeout.
BThe 'timeout' step does not work with shell commands like 'sh'.
CThe timeout unit is incorrectly set and defaults to seconds.
DThe pipeline agent does not support timeouts.
Attempts:
2 left
💡 Hint
Think about how Jenkins interrupts running shell commands.
🔀 Workflow
advanced
2:00remaining
Implementing Timeout with Retry in Jenkins Pipeline
Which Jenkins pipeline snippet correctly retries a build stage up to 3 times if it times out after 2 minutes each attempt?
A
stage('Retry Timeout') {
  steps {
    retry(3) {
      timeout(time: 2, unit: 'MINUTES') {
        sh 'run_tests.sh'
      }
    }
  }
}
B
stage('Retry Timeout') {
  steps {
    timeout(time: 2, unit: 'MINUTES') {
      retry(3) {
        sh 'run_tests.sh'
      }
    }
  }
}
C
stage('Retry Timeout') {
  steps {
    retry(3) {
      sh 'timeout 2m run_tests.sh'
    }
  }
}
D
stage('Retry Timeout') {
  steps {
    sh 'run_tests.sh'
    timeout(time: 2, unit: 'MINUTES') {
      retry(3) {
        echo 'Retrying'
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Timeout should wrap the command inside the retry block to retry on timeout.
Best Practice
expert
2:00remaining
Best Practice for Setting Build Timeout in Jenkins Declarative Pipeline
Which approach is the best practice to set a global build timeout of 15 minutes for all stages in a Jenkins declarative pipeline?
ASet the timeout in the Jenkins global configuration only.
BWrap each stage with a 'timeout' block set to 15 minutes.
C
Use the 'options' directive with 'timeout' at the pipeline level:
options { timeout(time: 15, unit: 'MINUTES') }
DUse a 'timeout' step inside the 'post' section to abort after 15 minutes.
Attempts:
2 left
💡 Hint
Consider how to apply timeout globally in declarative pipelines.