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

Provide currentBuild.isRestartedRun and .isRestartedStage global variables

    Details

    • Sprint:
      Declarative backlog
    • Similar Issues:

      Description

      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

        Attachments

          Issue Links

            Activity

            Hide
            abayer 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.

            Show
            abayer 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.
            Hide
            fnasser Fernando Nasser added a comment -

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

            Show
            fnasser Fernando Nasser added a comment - Fair enough.  Any viable way that achieves the same result is welcome.
            Hide
            fnasser 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.

             

             

            Show
            fnasser 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.    
            Hide
            fnasser Fernando Nasser added a comment -

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

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

              People

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

                Dates

                • Created:
                  Updated: