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

Provide currentBuild.isRestartedRun and .isRestartedStage global variables

    • Declarative backlog

      On a restarted stage, there is a when condition, isRestartedRun() that can be used to run or not a stage.  But there isn't anything that can be used to execute a bit different on a restart than in the original run.  This leads to workarounds like:

          stages {
              stage('Schedule') {
                  when

      {                 not\{ isRestartedRun() }

                  }
                  agent any
                  steps

      {                     myCommand 'isRestartedRun: false'             }

              }
              stage('Restart') {
                  when

      {                 isRestartedRun()             }

                  agent any
                  steps

      {                     myCommand 'isRestartedRun: true'             }

              }

       

      It would be much simpler and clearer to be able to just check for currentBuild.isRestartedRun wherever global variables are accessible

          [JENKINS-53193] Provide currentBuild.isRestartedRun and .isRestartedStage global variables

          Andrew Bayer added a comment -

          Due to the fun of plugin dependency trees, I can't actually add this to currentBuild, but I could definitely expose this either via a step (though I wouldn't want to call it isRestartedRun() to avoid confusion) or maybe a variable that gets added to the environment automatically. Lemme think on this.

          Andrew Bayer added a comment - Due to the fun of plugin dependency trees, I can't actually add this to currentBuild , but I could definitely expose this either via a step (though I wouldn't want to call it isRestartedRun() to avoid confusion) or maybe a variable that gets added to the environment automatically. Lemme think on this.

          Fair enough.  Any viable way that achieves the same result is welcome.

          Fernando Nasser added a comment - Fair enough.  Any viable way that achieves the same result is welcome.

          Maybe this deserves a separate JIRA, but it is certainly related:

          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.

           

           

          Fernando Nasser added a comment - Maybe this deserves a separate JIRA, but it is certainly related: 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.    

          isRestartedStage variable is needed as well (to match the when condition isRestartedStage() )

          Fernando Nasser added a comment - isRestartedStage variable is needed as well (to match the when condition isRestartedStage() )

          Jesse Glick added a comment -

          Special case of JENKINS-41272.

          Jesse Glick added a comment - Special case of JENKINS-41272 .

            Unassigned Unassigned
            fnasser Fernando Nasser
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: