Build timeouts in Jenkins - Time & Space Complexity
When Jenkins runs a build, it can stop the build if it takes too long. This is called a build timeout.
We want to understand how the time Jenkins spends checking for timeouts grows as the build runs longer.
Analyze the time complexity of this Jenkins pipeline snippet with a timeout block.
timeout(time: 10, unit: 'MINUTES') {
stage('Build') {
sh 'make build'
}
}
This code stops the build if it runs longer than 10 minutes by checking periodically during the build stage.
Jenkins checks the elapsed time repeatedly while the build runs.
- Primary operation: Periodic timeout checks during the build execution.
- How many times: The number of checks depends on how long the build runs and the check interval.
As the build time increases, Jenkins performs more timeout checks.
| Build Time (minutes) | Approx. Timeout Checks |
|---|---|
| 1 | Few checks (e.g., 6 if checking every 10 seconds) |
| 10 | More checks (e.g., 60 checks) |
| 100 | Many checks (e.g., 600 checks) |
Pattern observation: The number of timeout checks grows roughly in direct proportion to the build duration.
Time Complexity: O(n)
This means the time Jenkins spends checking for timeout grows linearly with how long the build runs.
[X] Wrong: "Timeout checks happen only once at the end of the build."
[OK] Correct: Jenkins actually checks repeatedly during the build to stop it early if needed, so the checks grow with build time.
Understanding how Jenkins manages build timeouts helps you explain how monitoring and control operations scale in real systems.
What if Jenkins checked for timeout only once every minute instead of every few seconds? How would the time complexity change?