I have a scripted jenkins pipeline with the code like this.
func_stage_1() {
try {
stage1
} catch {
}
}
func_stage_1()
Initially when I did not have the stage inside function, pipeline used to fail if a stage failed and exceptions were printed. After putting it inside function, it continues the whole pipeline even though one stage fails. How to fix this?
CodePudding user response:
Main functionality behind adding exception logic is to continue the process even though the stage is failed.
If you want to make the remaining process stop, if exception occurred then you have to do it in below way.
func_stage_1() {
try {
stage1
} catch(Exception err {
error "${err}" // stops the execution of remaining stages by throwing the exception
}
}
func_stage_1()