Here's what I think happens in your pipeline:
- The stage starts, and the timeout is set for 5 seconds.
- The sleep step starts, which sleeps for 10 seconds.
- After 5 seconds, the timeout is reached, and the first attempt of the stage is aborted.
However, the retry step kicks in and retries the entire stage because it's considered a single unit. The timeout option doesn't reset for each retry; it applies to the cumulative time spent in all attempts of the stage. Since the cumulative time spent in both attempts exceeds 5 seconds, the stage ultimately succeeds after the second try.
If you want to apply a timeout to each individual retry attempt, you may need to structure your pipeline differently, such as putting the timeout inside the retry block like this:
pipeline {
agent none
stages {
stage('With timeout') {
options {
retry(2) {
timeout(time: 5, unit: 'SECONDS')
}
}
steps {
sleep time: 10, unit: 'SECONDS'
}
}
}
}
With this configuration, each retry attempt should have its own 5-second timeout, and if the sleep step exceeds that time on any attempt, that individual attempt will be aborted.
Here's what I think happens in your pipeline:
However, the retry step kicks in and retries the entire stage because it's considered a single unit. The timeout option doesn't reset for each retry; it applies to the cumulative time spent in all attempts of the stage. Since the cumulative time spent in both attempts exceeds 5 seconds, the stage ultimately succeeds after the second try.
If you want to apply a timeout to each individual retry attempt, you may need to structure your pipeline differently, such as putting the timeout inside the retry block like this:
With this configuration, each retry attempt should have its own 5-second timeout, and if the sleep step exceeds that time on any attempt, that individual attempt will be aborted.