Reputation: 1398
I have a pipeline with some stages and logic. The only possible debugger is adding try-catch to each stage:
stage ("distribution"){
steps{
script{
try{
amd_distribution_distribute_bundle
}
catch (Exception e) {
echo e.toString()
}
}
}
}
however, if one stage fails, I need to stop the pipeline:
status = sh script: '''
set +x
python3.4 main.py --command create_bundle
''', returnStatus:true
}
}
}
if (status == 1) {
error("returning 1 from func")
}
but the try-catch from the pipeline actually cancel it (it proceed to other stages. is there a way to combine them?
Upvotes: 0
Views: 263
Reputation: 515
Instead of try/catch you can use a catchError
step. You can use the buildResult
or stageResult
arguments to set what the build result should be set to if the step throws an error:
catchError (stageResult: "FAILURE") {
sh script: # Your script here
}
Upvotes: 2