Reputation: 3114
I'm constructing a declarative Jenkins pipeline where i want to have timeout of a stage in a way that subsequent stage continue to run gracefully. I'm sure there are no inter-dependencies between stages in this usecase.
pipeline {
agent any
stages {
stage('Build-1') {
options {
timeout(time: 1, unit: 'HOURS')
}
steps {
echo 'Hello World 1'
}
}
stage('Build-2') {
steps {
echo 'Hello World 2'
}
}
}
}
In the above example, after timeout of stage Build-1
the pipeline aborts with following message:
Sending interrupt signal to process
Cancelling nested steps due to timeout
Here, stage Build-2
is not executed. Is there a way where despite the timeout in stage Build-1
, pipeline can continue to run stage Build-2
gracefully.
I'm referring to following documentation: https://jenkins.io/doc/book/pipeline/syntax/#options
Upvotes: 2
Views: 8818
Reputation: 6859
This may work:
pipeline {
agent any
stages {
stage('Build-1') {
options {
timeout(time: 1, unit: 'HOURS')
}
steps {
script {
try {
echo 'Hello World 1'
} catch (error) {
println "Error happened, continuing"
}
}
}
}
You may further examine whether the error
happened because of timeout, or for other reason.
Upvotes: 2