0
0
Jenkinsdevops~10 mins

Build timeouts in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Build timeouts
Start Build
Start Timer
Build Running
Check Timeout?
NoContinue Build
Yes
Abort Build
Build Ends
The build starts and a timer runs. If the build runs longer than the timeout, Jenkins aborts it. Otherwise, it continues until done.
Execution Sample
Jenkins
timeout(time: 5, unit: 'MINUTES') {
  sh 'sleep 300'
}
This Jenkins pipeline snippet runs a shell command that sleeps for 300 seconds with a 5-minute timeout.
Process Table
StepActionTimer StatusBuild StatusOutput
1Start build and timer0 min elapsedRunningBuild started
2Run shell command 'sleep 300'1 min elapsedRunningSleeping...
3Run shell command continues4 min elapsedRunningStill sleeping...
4Timer reaches 5 minutes5 min elapsedTimeout triggeredBuild aborted due to timeout
5Build endsStoppedAbortedBuild stopped because timeout exceeded
💡 Build aborted because the timeout of 5 minutes was reached while the sleep command was still running.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Timer (minutes elapsed)00145Stopped
Build StatusNot startedRunningRunningRunningTimeout triggeredAborted
Key Moments - 2 Insights
Why does the build abort exactly at 5 minutes?
Because the timeout is set to 5 minutes, Jenkins monitors the elapsed time and aborts the build as soon as it reaches this limit, as shown in step 4 of the execution table.
What happens if the build finishes before the timeout?
If the build finishes before the timeout, Jenkins stops the timer and completes the build normally. This is implied by the flow where 'Check Timeout?' leads to 'Continue Build' if no timeout occurs.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the build status at step 3?
AAborted
BNot started
CRunning
DCompleted
💡 Hint
Check the 'Build Status' column at step 3 in the execution table.
At which step does the timeout trigger the build abort?
AStep 2
BStep 4
CStep 5
DStep 3
💡 Hint
Look for 'Timeout triggered' in the 'Build Status' column in the execution table.
If the timeout was set to 10 minutes instead of 5, what would change in the execution table?
ABuild would never abort at 5 minutes
BTimer would reach 10 minutes before aborting
CBuild would abort at step 4
DBuild would abort immediately
💡 Hint
Refer to the 'Timer Status' and 'Build Status' columns and how timeout triggers abort.
Concept Snapshot
Build timeouts in Jenkins stop builds that run too long.
Use the 'timeout' step with time and unit.
If build exceeds time, Jenkins aborts it.
Prevents stuck or slow builds.
Example: timeout(time:5, unit:'MINUTES') { ... }
Full Transcript
In Jenkins, build timeouts help stop builds that take too long. When a build starts, Jenkins starts a timer. If the build finishes before the timeout, it completes normally. If the build runs longer than the timeout, Jenkins aborts it to save resources. For example, using the 'timeout' step with 5 minutes means if the build runs over 5 minutes, Jenkins stops it. This prevents builds from hanging forever. The execution table shows the timer increasing each step and the build status changing to aborted when the timeout is reached.