-
Bug
-
Resolution: Fixed
-
Minor
-
Jenkins v2.121.1, Pipeline: Declarative Plugin v1.3
The Jenkins Declarative Pipeline is experiencing non-deterministic results when entering the post steps for parallel stages. For example, when an error is raised in one of two parallel stages and the other stage succeeds, but finish around the same time, then the successful stage executes the failure post stage, instead of the successful.
stage("Parallel stages") { parallel { stage("Stage 1"){ agent none steps { script { // sleep 10 // when sleeping long enough, stages behave correctly. error("Which post step will get executed?") } } post { success { echo "Stage 1 success!" } failure { echo "Stage 1 failure!" } } } stage("Stage 2"){ agent none steps { script { echo "Stage 2 code executing..." } } post { success { echo "Stage 2 success!" } failure { echo "Stage 2 failure!" } } } } post { success { echo "Parallel post steps success!" } failure { echo "Parallel post steps failure!" } } }
So when Stage 1 has the sleep step commented out the results I see are:
[Stage 1] Stage 1 failure!
[Stage 2] Stage 2 failure!
Parallel post steps failure!
But when Stage 1 has the sleep step active, the results I see are:
[Stage 1] Stage 1 failure!
[Stage 2] Stage 2 success!
Parallel post steps failure!
I should expect the second scenario in all situations, right?
- links to
Regrettably, it actually is deterministic, it's just kinda crappy. =) The failure/success doesn't actually refer to failure/success of the individual stage, but of the build as a whole at the time that the post block is evaluated. So if stage 1 hasn't finished yet when stage 2 finishes, the build status is still success.
This is, yes, annoying. There's an open ticket for better per-stage status tracking, and independent of that, I might be able to tweak the success condition specifically to be more stage-specific (though failure/unstable/aborted would still have to look at the overall build status). Will update once I have a chance to experiment.