-
Bug
-
Resolution: Unresolved
-
Major
-
Jenkins 2.303.2
The Utils.markStageWithTag method searches for executing nodes based on the stageName using findStageFlowNodes. This doesn't distinguish between multiple stages that can be executing at the same time with the same name (such as in scripted or declarative pipeline where a sequence of stages can be constructed to be used multiple times).
To demonstrate this, the following scripted pipeline will pick a random, but not the first, stage to mark a stages a skipped for conditional, but the first stage is always marked.
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils import java.util.Random def script = this script.node(label: 'overwatch') { def workers = [:] int parallelSampleCount = 4 Random rand = new Random() int testNumberToSkipOn = 1 + rand.nextInt(parallelSampleCount - 1) for(int i = 0; i < parallelSampleCount; ++i) { int currentValue = i workers["test_${i}"] = { script.stage('first') { script.echo "Stage to skip on is: ${testNumberToSkipOn}" } script.stage('second') { script.sleep(10) if(currentValue == testNumberToSkipOn) { Utils.markStageSkippedForConditional('second') Utils.markStageSkippedForConditional('third') // to see what happens } script.sleep(10) } script.stage('third') { echo 'I don\'t get marked as skipped for conditional.' } } } script.parallel(workers) }
This results in the 'second' stage in the test_0 parallel leg always being marked skipped for conditional, even though it is being run by test_3 (in this case). The expectation is it would be relevant for the currently running stage, as shown:
Is there a mechanism to achieve this using other means from within a step of a stage in a scripted (non-declarative) pipeline in particular?