Hi all,
sorry, there went something wrong with formatting in my first email. :-/
Here is the hopefully correctly formatted version:
I can't get the timeout option working correctly in pipeline scripts.
What I expect is that if a define a timeout on the toplevel in the
Jenkinsfile and a step is taking longer than this timeout the step is
stopped forcibly and the build is marked as failed/aborted.
This is at least what the documentation suggests
(
https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#timeout-enforce-time-limit):
"If the time limit is reached, an exception
(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) is
thrown, which leads in aborting the build..."
I tried declarative and imperative syntax with the latest 2.229 running
in a docker container. The step is stopped, but the exception is not
thrown and thus the build has a successed status:
```
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/timeout_test_declarative
[Pipeline] {
[Pipeline] timeout
Timeout set to expire in 5 sec
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Sleep)
[Pipeline] sh
Cancelling nested steps due to timeout
Sending interrupt signal to process
Terminated
signal TERM received, script exit code 0
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
```
The pipeline script is the following. Please note that I need to catch
the term signal in the shell, otherwise the killed sleep exits itself
with exit code 143 which renders the step as failed only because of the
exit code and not because of the timeout:
```
pipeline{
// Run only on agents tagged as shift
agent any
options {
timeout(time: 5, unit: 'SECONDS')
}
stages{
stage('Sleep') {
steps {
sh """#!/bin/bash
sigterm()
{
echo "signal TERM received, script exit code 0"
exit 0
}
trap 'sigterm' TERM
while true; do
sleep 1
done
"""
}
}
}
}
```
Anything I missed here?
Regards
Georg