It's a known Jenkins issue that pipeline retry operation doesn't retry when there is a timeout inside of it.
Surely there are some workarounds to force retry
(or substitute) to work after a timeout occurs?
Sample code where retry
is not triggered:
retry(3) {
timeout(time: 5, unit: 'MINUTES') {
// Something that can fail
}
}
Unless caught, the timeout error (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
) causes the entire job to abort.
A good workaround, as suggested by Basil Crow here is to insert try - catch
between retry
and timeout
to consume the timeout error (FlowInterruptedException
) without passing it to retry
. As soon as we replace FlowInterruptedException
with a custom error, retry
kicks in and starts cooperating correctly even with timeout
inside.
Example:
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
retry(3) {
try {
timeout(time: 5, unit: 'MINUTES') {
// something that can fail
} // timeout ends
} catch (FlowInterruptedException e) {
// we re-throw as a different error, that would not
// cause retry() to fail (workaround for issue JENKINS-51454)
error 'Timeout!'
} // try ends
} // retry ends
JENKINS-51454 has been fixed in jenkinsci/workflow-basic-steps-plugin#144 and released in 2.24 (Changelog).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With