Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-68614

markStageWithTag (affecting markStageSkippedForConditional and others) can affect the wrong stage executing at the same time


      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') {
                          if(currentValue == testNumberToSkipOn) {
                              Utils.markStageSkippedForConditional('third') // to see what happens
                      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?


            Unassigned Unassigned
            bscriver Brent Scriver
            1 Vote for this issue
            2 Start watching this issue