I've a pipeline with stages where one of the stage, intermittently takes longer than expectation and hence using timeout
to abort it. But if the stage is aborted, build also marked as aborted. Following is the code for pipeline -
pipeline {
agent any
stages {
stage('First') {
options {
timeout(time: 10, unit: 'SECONDS')
}
steps {
script {
catchError(buildResult: 'SUCCESS') {
echo "Executing stage I"
sleep 12
}
}
}
}
stage('Second') {
steps {
script {
echo "Executing stage II"
}
}
}
}
}
Even though the stage is marked as Aborted
, I want to mark build as Success
. Can you please help how I can achieve this?
timeout
step inside the script block, and you also want to usetry { } catch { }
instead ofcatchError
, and you want to make sure thattimeout
is inside yourtry
block. Finally, you want to make certain you are only catching the exception raised on timeout and not all exceptions so that you don't accidentally mark an actual failed build as successful; you only want to catch the ones that hit the timeout.