Bird
Raised Fist0
Jenkinsdevops~20 mins

Build timeouts in Jenkins - Practice Problems & Coding Challenges

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

Practice

(1/5)
1. What is the main purpose of using timeout in a Jenkins build step?
easy
A. To log the build step output for debugging
B. To increase the build step execution time automatically
C. To restart the build step if it fails
D. To limit how long a build step runs to avoid stuck builds

Solution

  1. Step 1: Understand the role of timeout in Jenkins

    The timeout directive is used to set a maximum time limit for a build step to run.
  2. Step 2: Identify the benefit of limiting build step time

    Limiting time prevents builds from hanging indefinitely and wasting resources.
  3. Final Answer:

    To limit how long a build step runs to avoid stuck builds -> Option D
  4. Quick Check:

    Timeout limits build step time = A [OK]
Hint: Timeout stops long builds to save resources [OK]
Common Mistakes:
  • Thinking timeout extends build time
  • Confusing timeout with retry logic
  • Assuming timeout logs output automatically
2. Which of the following is the correct syntax to set a timeout of 10 minutes in a Jenkins pipeline?
easy
A. timeout(time: 10, unit: 'MINUTES') { /* steps */ }
B. timeout(10 minutes) { /* steps */ }
C. timeout { time: 10, unit: 'MINUTES' }
D. timeout(time=10, unit='minutes') { /* steps */ }

Solution

  1. Step 1: Recall Jenkins timeout syntax

    The correct syntax uses named parameters: timeout(time: 10, unit: 'MINUTES').
  2. Step 2: Check each option for syntax correctness

    timeout(time: 10, unit: 'MINUTES') { /* steps */ } matches the correct syntax. The other options have syntax errors or wrong parameter formats.
  3. Final Answer:

    timeout(time: 10, unit: 'MINUTES') { /* steps */ } -> Option A
  4. Quick Check:

    Named params with colon and quotes = B [OK]
Hint: Use named params with colon and quotes for timeout [OK]
Common Mistakes:
  • Using parentheses without named params
  • Wrong parameter separators like = instead of :
  • Missing quotes around unit string
3. Given this Jenkins pipeline snippet:
timeout(time: 1, unit: 'MINUTES') {
  sh 'sleep 90'
}

What will happen when this pipeline runs?
medium
A. The build step will complete successfully after 90 seconds
B. The build step will timeout and be aborted after 1 minute
C. The build step will ignore the timeout and run for 90 seconds
D. The build will fail immediately due to syntax error

Solution

  1. Step 1: Analyze the timeout and sleep duration

    The timeout is set to 1 minute, but the shell command sleeps for 90 seconds (1.5 minutes).
  2. Step 2: Understand timeout behavior

    Since the sleep exceeds the timeout, Jenkins will abort the build step after 1 minute.
  3. Final Answer:

    The build step will timeout and be aborted after 1 minute -> Option B
  4. Quick Check:

    Sleep > timeout causes abort = D [OK]
Hint: If step runs longer than timeout, Jenkins aborts it [OK]
Common Mistakes:
  • Assuming step completes despite timeout
  • Confusing timeout unit or value
  • Thinking syntax error occurs here
4. You added a timeout to your Jenkins pipeline but it does not abort the build when expected. Which is the most likely cause?
medium
A. The timeout unit is misspelled or invalid
B. The timeout block is placed outside the pipeline script
C. The timeout value is set longer than the step duration
D. The Jenkins server is offline

Solution

  1. Step 1: Check timeout configuration

    The most likely cause is that the timeout value is set longer than the actual step duration, so no timeout occurs even if expected.
  2. Step 2: Evaluate other options

    Timeout block outside pipeline or invalid unit would cause syntax errors preventing execution. Server offline prevents builds from running.
  3. Final Answer:

    The timeout value is set longer than the step duration -> Option C
  4. Quick Check:

    Timeout value longer than step = A [OK]
Hint: Verify timeout value vs step duration if no abort [OK]
Common Mistakes:
  • Placing timeout outside pipeline block
  • Setting timeout longer than step time expecting abort
  • Ignoring Jenkins server status
5. You want to ensure a Jenkins build step is aborted if it runs longer than 5 minutes, but you also want to retry the step up to 2 times if it fails due to timeout. Which pipeline snippet correctly implements this?
hard
A. retry(2) { timeout(time: 5, unit: 'MINUTES') { sh 'run-step.sh' } }
B. timeout(time: 5, unit: 'MINUTES') { retry(2) { sh 'run-step.sh' } }
C. timeout(time: 5, unit: 'MINUTES', retry: 2) { sh 'run-step.sh' }
D. retry(2, timeout(time: 5, unit: 'MINUTES')) { sh 'run-step.sh' }

Solution

  1. Step 1: Understand retry and timeout nesting

    To retry a step if it times out, the timeout block must be inside the retry block so the whole timeout step is retried.
  2. Step 2: Evaluate each option's structure

    retry(2) { timeout(time: 5, unit: 'MINUTES') { sh 'run-step.sh' } } correctly nests timeout inside retry. timeout(time: 5, unit: 'MINUTES') { retry(2) { sh 'run-step.sh' } } retries the inner command but timeout applies only once. The remaining options use invalid syntax.
  3. Final Answer:

    retry(2) { timeout(time: 5, unit: 'MINUTES') { sh 'run-step.sh' } } -> Option A
  4. Quick Check:

    retry outside timeout retries whole timeout block = A [OK]
Hint: Put timeout inside retry to retry timed-out steps [OK]
Common Mistakes:
  • Placing retry inside timeout causing no retry on timeout
  • Using invalid parameters in timeout
  • Misunderstanding retry scope
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