I want to skip stage in jenkins if my build is getting failed or time exceeds and want directly jump on destroy stage I Tried
stage('Build') {
options {
timeout(time: 10, unit: 'MINUTES')
}
steps {
// Build steps
}
}
// Other stages
}
} but i am unable to destroy my build, the build gets aborted also tried this :
pipeline {
agent any
stages {
stage('Stage 1') {
steps {
// Add your stage 1 steps here
}
}
stage('Stage 2') {
steps {
// Add your stage 2 steps here
}
}
// Repeat for stages 3 to 8
stage('Last Stage') {
steps {
// Add your last stage steps here
}
}
}
post {
always {
script {
if (currentBuild.result == 'FAILURE') {
stage('Last Stage') {
// Add your last stage steps here
}
}
}
}
}
But this also didn't worked for me
not able to jump on destroy stage if getting error r timeout not able to jump on destroy stage if getting error r timeout
what exactly i want is - This I want
You can try this :
} catch (error) {
println error
failure(message: "Timeout reached.")
}
You can add a post failure stage that destroys if that stage is reached:
post {
failure {
// destroy steps
}
}
If your build fails then it must reach this step. However if it aborts due to timeout it will not come here. You will instead have to catch the timeout error and convert it to a failure by doing this:
} catch (error) {
println error
failure(message: "Timeout reached.")
}
Look at this question and its answer to see how you can do that.
You could also put your destroy logic in a function and call that function in both failure and aborted cases:
def destroy () {
...
}
...
post {
failure {
destroy()
}
aborted {
destroy()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With