I know that one can set a timeout for the entire pipeline script or a specific stage using options
, but is there a way to set a timeout for a group of stages? For example a total 10 minute timeout (not 10 minute each) for only 3 out of the 5 stages, and let the other 2 run freely.
1
votes
1 Answers
5
votes
Sure, you can create nested stages and define the timeout
option for the parent stage:
pipeline {
agent any
stages{
stage('Stage A') {
options{
timeout( time: 10, unit: 'SECONDS' )
}
stages {
stage('Stage A1') {
steps {
sleep( time: 4, unit: 'SECONDS' )
}
}
stage('Stage A2') {
steps {
sleep( time: 4, unit: 'SECONDS' )
}
}
stage('Stage A3') {
steps {
sleep( time: 4, unit: 'SECONDS' )
}
}
}
}
}
}
Stage A3 will never be executed because of the parent timeout. It will be marked as "aborted":
stages { stage {...} stage {...}}
– MaratC