I am looking for the cleanest way to exit a declarative Jenkins pipeline, with a success status. While exiting with an error is very neat using error step , I couldn't find any equal way to exit with success code. E.G:
stage('Should Continue?') {
when {
expression {skipBuild == true }
}
steps {
echo ("Skiped Build")
setBuildStatus("Build complete", "SUCCESS");
// here how can I abort with sucess code?
// Error Would have been:
// error("Error Message")
}
}
stage('Build') {
steps {
echo "my build..."
}
}
For Example with a scripted build, I could achieve it with the following code:
if (shouldSkip == true) {
echo ("'ci skip' spotted in all git commits. Aborting.")
currentBuild.result = 'SUCCESS'
return
}
While I am aware of the ability to add a script step to my declarative pipieline, I was hoping to find a cleaner way.
Another approach could be throwing an error and catch it somewhere down the line, but again it quite messy.
Is there a cleaner way?