Reputation: 15
in my pipeline one of the stage is exited with code 1 and still pipeline is passing. I want to fail the pipeline stage with exception when it is exiting with code 1.
Here is stage code:
stage('Stage A'){
steps{
script{
container('A'){
sh "$Command"
def exitCode = sh 'echo $?'
if (exitCode == 1) {
sh "exit 1"
}
}
}
}
}
Upvotes: 1
Views: 624
Reputation: 14594
If you want to error out the Pipeline you can use error signal.
def exitCode = sh script:"$Command", returnStatus:true
if (exitCode == 1) {
error "Exit code is 1, so erroring out!"
}
Upvotes: 1