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

isRestartedRun() is not reset after a successful stage

XMLWordPrintable

    • Declarative backlog

      In a longer pipeline it is possible that one needs to check if a step has been restarted more than one time.

      Lets say steps 3 and 7 must behave different when they are restarted.

      If we restart the step 3 the isRestartedRun() will be true and trick step 7 in believing it has been restarted (when it was not, 3 was the one restarted).

      We need a way to reset this, perhaps after the first step after the restart is completed.

      I marked this as Critical because it really misleads the code in later stages into executing the wrong code based on misinformation.  Here is one example:

      stages {
      stage('DoWork') {
      when

      { not\{ isRestartedRun() }

      }
      agent any
      steps

      { <Do something the regular way> ) }

      }
      }
      stage('RestartWork') {
      when

      { isRestartedRun() }
      agent any
      steps { <Do it differently because the step was restarted and some things cannot/should not be done again on restart> ) }
      }
      }
      stage('FlagTest') {
      when { isRestartedRun() }

      agent any
      steps

      { echo "isRestartedRun should be false here" }

      }
      }

       

      The last stage above does get executed, as shown in this console output:
      [Pipeline] echoisRestartedRun should be false here
       

       

            Unassigned Unassigned
            fnasser Fernando Nasser
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: