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

Restart from Stage doesn't restore global variable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • None
    • Jenkins ver. 2.121.2 with up-to-date plugins

      The attached Jenkinsfile can be used to reproduce this issue.

      Running the Pipeline the first time, everything works as expected:

      run a)
      ------

      [Pipeline] {
      [Pipeline] timestamps
      [Pipeline] {

      [Pipeline] stage
      [Pipeline] { (one)

      [Pipeline] script
      [Pipeline]

      { [Pipeline] echo 00:00:06.159 simpletest-17 [Pipeline] }

      [Pipeline] // script

      [Pipeline] }
      [Pipeline] // stage

      [Pipeline] stage
      [Pipeline] { (two)
      [Pipeline] script
      [Pipeline]

      { [Pipeline] echo 00:00:09.465 simpletest-17 [Pipeline] echo 00:00:10.274 simpletest-17 [Pipeline] }

      [Pipeline] // script

      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // timestamps

      [Pipeline] }
      [Pipeline] // node

      [Pipeline] End of Pipeline
      Finished: SUCCESS

       

      If it is restarted from stage 'two', the value of the global Map member is null. I would expect to have the value from the last run there:

       

      run b) - restart from stage two
      -------------------------------
      [Pipeline] timestamps
      [Pipeline] {
      [Pipeline] stage
      [Pipeline]

      { (one) Stage "one" skipped due to this build restarting at stage "two" [Pipeline] }

      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (two)
      [Pipeline] script
      [Pipeline]

      { [Pipeline] echo 00:00:07.975 simpletest-18 [Pipeline] echo 00:00:08.408 null --8<-- i would expect to get 'simpletest-17' instead of 'null' --8<-- [Pipeline] }

      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // timestamps
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS

       

          [JENKINS-52774] Restart from Stage doesn't restore global variable

          Manuel Traut created issue -
          Daniel Kurzynski made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]
          Daniel Kurzynski made changes -
          Component/s New: blueocean-plugin [ 21481 ]

          Daniel Kurzynski added a comment - - edited

          We also experienced this issue. We provide a shared library which has global state. Unfortunately, this state get's not restored and thus restarting is not possible. We try to restart the pipeline directly from blue ocean.

          As everything anyway needs to be serializable it should be possible to store and restore the pipeline's state. 

          Daniel Kurzynski added a comment - - edited We also experienced this issue. We provide a shared library which has global state. Unfortunately, this state get's not restored and thus restarting is not possible. We try to restart the pipeline directly from blue ocean. As everything anyway needs to be serializable it should be possible to store and restore the pipeline's state. 

          Olivier Lamy added a comment -

          abayer I reproduced this. any idea? thanks

          Olivier Lamy added a comment - abayer I reproduced this. any idea? thanks
          Andrew Bayer made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Component/s Original: blueocean-plugin [ 21481 ]
          Component/s Original: pipeline-stage-step-plugin [ 21709 ]

          Andrew Bayer added a comment -

          This is expected - anything outside the pipeline block definitely won’t be preserved, and shared libraries that have state won’t be preserved either. We’re not actually saving the execution state of the Pipeline, we’re restarting it from the selected stage with all inputs and stashes preserved.

          Andrew Bayer added a comment - This is expected - anything outside the pipeline block definitely won’t be preserved, and shared libraries that have state won’t be preserved either. We’re not actually saving the execution state of the Pipeline, we’re restarting it from the selected stage with all inputs and stashes preserved.

          Manuel Traut added a comment -

          abayer doesn't this make the feature somehow useless?

          What's the reason not storing the complete pipeline status as it is probably done during jenkins restarts?

          Manuel Traut added a comment - abayer doesn't this make the feature somehow useless? What's the reason not storing the complete pipeline status as it is probably done during jenkins restarts?

          My use case is that I need my step to work differently on restart, so I need to save a value from the previous attempt.

          The restart feature is wonderful and flexible but loses all data, so we have currently a mandatory process for all restarts that need some data from the previous attempt:

           

          write to file -> stash (restart) unstash -> read from file

           

          It seems to be a very common use case, so some way of preserving some data will very much enhance the experience with restarts.

           

          Fernando Nasser added a comment - My use case is that I need my step to work differently on restart, so I need to save a value from the previous attempt. The restart feature is wonderful and flexible but loses all data, so we have currently a mandatory process for all restarts that need some data from the previous attempt:   write to file -> stash (restart) unstash -> read from file   It seems to be a very common use case, so some way of preserving some data will very much enhance the experience with restarts.  

          Andrew Bayer added a comment -

          Lemme think on this. It may be viable for us to be able to do something like record some information in the previous build explicitly and then be able to refer to that data in the restarted build. Like (and this is really, really hand-wave-y, so don't take this as anything but speculation) this, maybe?

          stage('some-stage') {
            steps {
              setPersistentEnv(key: "FOO", value: "abcd")
            }
          }
          stage('stage-to-restart') {
            steps {
              echo "FOO is ${env.FOO}"
            }
          }
          

          Again, totally not sure if that's actually useful or if it's even possible to implement cleanly.

          Andrew Bayer added a comment - Lemme think on this. It may be viable for us to be able to do something like record some information in the previous build explicitly and then be able to refer to that data in the restarted build. Like (and this is really, really hand-wave-y, so don't take this as anything but speculation) this, maybe? stage( 'some-stage' ) { steps { setPersistentEnv(key: "FOO" , value: "abcd" ) } } stage( 'stage-to-restart' ) { steps { echo "FOO is ${env.FOO}" } } Again, totally not sure if that's actually useful or if it's even possible to implement cleanly.

            Unassigned Unassigned
            manut Manuel Traut
            Votes:
            21 Vote for this issue
            Watchers:
            25 Start watching this issue

              Created:
              Updated:
              Resolved: