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

isRestartedRun() is not reset after a successful stage

    Details

    • Sprint:
      Declarative backlog
    • Similar Issues:

      Description

      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
       

       

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            I think the direction I'm going to go with this is to add a new isRestartedStage() when condition that will specifically be true just when checked on the stage that we're restarting at, not with any subsequent stages. I can see valid use cases for isRestartedRun() being true for all stages executed in a restarted run, but the granularity is worth having as well.

            Show
            abayer Andrew Bayer added a comment - I think the direction I'm going to go with this is to add a new isRestartedStage() when condition that will specifically be true just when checked on the stage that we're restarting at, not with any subsequent stages. I can see valid use cases for isRestartedRun() being true for all stages executed in a restarted run, but the granularity is worth having as well.
            Hide
            fnasser Fernando Nasser added a comment -

            Good idea: the best of two worlds.

             

            But please don't forget to create a variable as well (see JENKINS-53193  for the isRestartedRun case)

            Show
            fnasser Fernando Nasser added a comment - Good idea: the best of two worlds.   But please don't forget to create a variable as well (see JENKINS-53193   for the isRestartedRun case)
            Hide
            abayer Andrew Bayer added a comment -

            PR up adding the new isRestartedStage() when condition - https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/293

            Show
            abayer Andrew Bayer added a comment - PR up adding the new isRestartedStage() when condition - https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/293
            Hide
            fnasser Fernando Nasser added a comment -

            Andrew Bayer In the example above, DoWork is the stage that fails and is restarted.  So 

            when { not{ isRestartedStage() }

            will allow it to be skipped.

            But in that case the RestartWork stage will not run with

            when { isRestartedStage() }

            because it was not it that failed (but DoWork).

            Note that I only had to use those two stages because there is no way to test inside the stage if it is a restart or the initial run.

            My apologies, I liked the isRestartedStage idea, but for my case above it is only useful as a variable.

            Basically all the when conditions are only useful to skip re-executing the step that failed (assuming you manually did what it was supposed to do), but they do not help in doing an alternative action in case of a restart.  That will only be achieved with JENKINS-53193

            Show
            fnasser Fernando Nasser added a comment - Andrew Bayer In the example above, DoWork is the stage that fails and is restarted.  So  when { not{ isRestartedStage() } will allow it to be skipped. But in that case the RestartWork stage will not run with when { isRestartedStage() } because it was not it that failed (but DoWork). Note that I only had to use those two stages because there is no way to test inside the stage if it is a restart or the initial run. My apologies, I liked the isRestartedStage idea, but for my case above it is only useful as a variable. Basically all the when conditions are only useful to skip re-executing the step that failed (assuming you manually did what it was supposed to do), but they do not help in doing an alternative action in case of a restart.  That will only be achieved with  JENKINS-53193

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                fnasser Fernando Nasser
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: