Instead of adding a post section at each step, I found some solution that should not work in the declarative pipeline from my point of view, but it works. All you need to do is override stage :
def stage(String name, Closure cl) { echo "Stage: ${name}" try { cl() } catch (Exception e) {
The strangest thing for me is that after the failure of the stage, the other stages are skipped, as it should be. Here is the conclusion:
14:05:14 Stage: First stage [Pipeline] script [Pipeline] { [Pipeline] sh 14:05:14 + echo first 14:05:14 first [Pipeline] } [Pipeline] // script [Pipeline] echo 14:05:14 Stage: Second stage [Pipeline] echo 14:05:14 second [Pipeline] echo 14:05:14 Stage: Fail stage [Pipeline] error [Pipeline] error [Pipeline] echo 14:05:14 Stage: Final stage Stage "Final stage" skipped due to earlier failure(s) [Pipeline] echo 14:05:14 Stage: Declarative: Post Actions [Pipeline] echo 14:05:14 Failed stage: Fail stage [Pipeline] echo 14:05:14 Error message: failed [Pipeline] } [Pipeline] // timestamps [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: failed Finished: FAILURE
source share