I am trying to run conditional steps in a Jenkins scripted pipeline, however I am not sure how to only run a step if a previous step was successful. For instance, in the following I only want to run the 'Push Artifacts' stage if the 'Test' stage was successful:
node ('docker2') {
stage ('Build') {
// build application
}
stage ('Test') {
// run tests
}
stage ('Push Artifacts') {
if (Tests Were Successful) {
// push to artifactory
}
}
}
I know that declarative pipelines allow you to use 'post' conditions, but my understanding of declarative vs. scripted pipelines in Jenkins is that scripted pipelines offer more flexibility. Is there a way to run stages based on other stages' success in a scripted pipeline?
stageto be invoked if the build result is anything other thanSUCCESSon entry (e.g.UNSTABLE). This can't go in apostblock, as the stage itself can fail the build. - simon.watts