Options directive (timeout, retry) in Jenkins - Time & Space Complexity
When using Jenkins options like timeout and retry, it's important to understand how they affect the total time your pipeline runs.
We want to see how the execution time grows as retries increase or timeout limits change.
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
options {
timeout(time: 5, unit: 'MINUTES')
retry(3)
}
stages {
stage('Example') {
steps {
sh 'echo Hello World'
}
}
}
}
This pipeline runs a simple shell command with a timeout of 5 minutes and retries up to 3 times on failure.
Look for repeated attempts and time limits that affect execution.
- Primary operation: The retry block repeats the stage steps on failure.
- How many times: Up to 3 retries, so the steps can run up to 4 times total (1 initial + 3 retries).
The total execution time can grow with the number of retries allowed.
| Retries Allowed (n) | Max Attempts |
|---|---|
| 1 | 2 (1 initial + 1 retry) |
| 3 | 4 (1 initial + 3 retries) |
| 5 | 6 (1 initial + 5 retries) |
Pattern observation: Each retry adds one more possible full execution of the steps, increasing total time linearly.
Time Complexity: O(n)
This means the total execution time grows linearly with the number of retries allowed.
[X] Wrong: "Timeout limits the total pipeline time regardless of retries."
[OK] Correct: Timeout applies per attempt, so retries can multiply total time beyond the single timeout limit.
Understanding how retry and timeout options affect pipeline duration shows you can reason about pipeline behavior and resource use, a key skill in DevOps roles.
"What if we changed retry(3) to retry(0)? How would the time complexity change?"