-
Bug
-
Resolution: Not A Defect
-
Major
Simple example:
node('master') { try { timeout(time: 5, unit: 'SECONDS') { try { sleep(30) } catch (err) { echo "For some reason, this catch is activated. Error: ${err.getMessage()}" } echo "This should not be executed, but it is!" } } catch (err) { echo "I expect that this catch will be activated. Error: ${err.getMessage()}" } }
I expect that when a timeout is reached, the exception will be caught by the try-catch that surrounds the "timeout" step.
But actually, it is caught by the most inner try-catch.
My goal here is to set timeout to set of actions and if the timeout is reached, I want them all to stop. I also want to have more try-catch inside for handling other issues.
But the actual behavior is that when the timeout is reached, the most internal catch handles it instead of the try-catch that surrounds the timeout step.
This issue is similar to JENKINS-39266. I do not understand why it was closed.
By the way, the
err.getMessage()
prints "null", which is also a problem.
- relates to
-
JENKINS-40839 pipeline timeout doesn't kill the job
-
- Resolved
-
-
JENKINS-28822 Can't distinguish between durable task abort and failure in workflow plugin
-
- Resolved
-
-
JENKINS-51454 Pipeline retry operation doesn't retry when there is a timeout inside of it
-
- Resolved
-
Fortunately or not, this is as-designed behavior. try/catch is a part of generic Groovy DSL. If you do not expecify explicit type of exception to be caught, it will catch everything including Jenkins Pipeline exceptions (e.g. blacklisted methods from script security). Once you start doing try/catch in Pipeline, you take full responsibility for exception handling.
CC svanoort abayer