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

652 views
Skip to first unread message

manut@linutronix.de (JIRA)

unread,
Jul 27, 2018, 7:23:02 AM7/27/18
to jenkinsc...@googlegroups.com
Manuel Traut created an issue
 
Jenkins / Bug JENKINS-52774
Restart from Stage doesn't restore global variable
Issue Type: Bug Bug
Assignee: Unassigned
Attachments: Jenkinsfile
Components: pipeline-stage-step-plugin
Created: 2018-07-27 11:22
Environment: Jenkins ver. 2.121.2 with up-to-date plugins
Priority: Minor Minor
Reporter: Manuel Traut

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

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

daniel.kurzynski@sap.com (JIRA)

unread,
Jul 30, 2018, 10:15:02 AM7/30/18
to jenkinsc...@googlegroups.com

daniel.kurzynski@sap.com (JIRA)

unread,
Jul 30, 2018, 10:18:02 AM7/30/18
to jenkinsc...@googlegroups.com

daniel.kurzynski@sap.com (JIRA)

unread,
Jul 30, 2018, 10:21:02 AM7/30/18
to jenkinsc...@googlegroups.com
Daniel Kurzynski commented on Bug JENKINS-52774
 
Re: Restart from Stage doesn't restore global variable

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. 

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

daniel.kurzynski@sap.com (JIRA)

unread,
Jul 30, 2018, 10:22:02 AM7/30/18
to jenkinsc...@googlegroups.com
Daniel Kurzynski edited a comment on Bug JENKINS-52774
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. 

olamy@apache.org (JIRA)

unread,
Jul 30, 2018, 6:53:01 PM7/30/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Jul 30, 2018, 6:58:02 PM7/30/18
to jenkinsc...@googlegroups.com
Andrew Bayer updated an issue
 
Change By: Andrew Bayer
Component/s: pipeline-model-definition-plugin
Component/s: blueocean-plugin
Component/s: pipeline-stage-step-plugin

andrew.bayer@gmail.com (JIRA)

unread,
Jul 30, 2018, 7:00:02 PM7/30/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-52774
 
Re: Restart from Stage doesn't restore global variable

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.

manut@linutronix.de (JIRA)

unread,
Jul 31, 2018, 10:49:02 AM7/31/18
to jenkinsc...@googlegroups.com

Andrew Bayer 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?

fnasser@redhat.com (JIRA)

unread,
Aug 22, 2018, 2:32:02 PM8/22/18
to jenkinsc...@googlegroups.com

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@gmail.com (JIRA)

unread,
Aug 22, 2018, 3:08:01 PM8/22/18
to jenkinsc...@googlegroups.com

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.

fnasser@redhat.com (JIRA)

unread,
Aug 22, 2018, 3:54:02 PM8/22/18
to jenkinsc...@googlegroups.com

Wow!  That would indeed solve my problem at least: I just need to save a number.  For a few values this would be more than enough.  And for something more elaborate the stash/unstash would be justifiable.

This could perhaps provide another workaround for https://issues.jenkins-ci.org/browse/JENKINS-53193  as checking for the value of a variable can indicate if it is a restart or not.

 

andrew.bayer@gmail.com (JIRA)

unread,
Aug 22, 2018, 3:59:03 PM8/22/18
to jenkinsc...@googlegroups.com

I feel like it's probably not ideal for that latter scenario, but I'll talk about that over on JENKINS-53913. =)

andrew.bayer@gmail.com (JIRA)

unread,
Aug 22, 2018, 3:59:03 PM8/22/18
to jenkinsc...@googlegroups.com

daniel.kurzynski@sap.com (JIRA)

unread,
Oct 11, 2018, 5:46:03 AM10/11/18
to jenkinsc...@googlegroups.com
Daniel Kurzynski commented on Bug JENKINS-52774
 
Re: Restart from Stage doesn't restore global variable

What about the original issue? Is there a plan to restore more in the future than just the stashes. 
Our use case is, that we are reading some configuration in the init stage and store them in a global variable or singleton object (object defined in vars of a lib). The configuration is basically about which stages in the declarative pipeline should be skipped but it contains also information the define the behavior of stages, e.g. where to deploy. 
Without that configuration it does not make sense to restart at a certain stage, because it will not skip stages as defined in the configuration or deployment information are missing. 
Thus, we need to possibility to restore additional state or have some initialization method in case the pipeline is restarted at a later state.

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

daniel.kurzynski@sap.com (JIRA)

unread,
Oct 11, 2018, 5:48:03 AM10/11/18
to jenkinsc...@googlegroups.com
Daniel Kurzynski edited a comment on Bug JENKINS-52774
What about the original issue? Is there a plan to restore more in the future than just the stashes. 
Our use case is, that we are reading some configuration in the init stage and store them in a global variable or singleton object (object defined in vars of a lib). The configuration is basically about which stages in the declarative pipeline should be skipped but it contains also information the to define the behavior of stages, e.g. where to deploy. 

Without that configuration it does not make sense to restart at a certain stage, because it will not skip stages as defined in the configuration or deployment information are missing. 
Thus, we need to the possibility to restore additional state or have some initialization method in case the pipeline is restarted at a later state stage .

andrew.bayer@gmail.com (JIRA)

unread,
Nov 16, 2018, 1:28:05 PM11/16/18
to jenkinsc...@googlegroups.com

Daniel Kurzynski - no, just stashes - preserving program state (like global variables or singletons) is a deeper, more complex problem area than Declarative goes, and is replete with painpoints. Sorry.

fnasser@redhat.com (JIRA)

unread,
Nov 16, 2018, 5:02:02 PM11/16/18
to jenkinsc...@googlegroups.com

Daniel Kurzynski I saved some state in a file and if it fails and is restarted I read what I need from that file (you need set preserveStashes() I believe, I did it but I am not sure). It worked fine. For skipping steps, etc., there is a JIRA to get the isRestartedRun() and isRestartedStage() into variables that can be used outside of the when{}

amleszk@gmail.com (JIRA)

unread,
Nov 2, 2019, 2:24:03 PM11/2/19
to jenkinsc...@googlegroups.com

Andrew Bayer This issue is affecting us also, if you can suggest a temporary work around that would help us Thanks

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

amleszk@gmail.com (JIRA)

unread,
Nov 2, 2019, 2:27:04 PM11/2/19
to jenkinsc...@googlegroups.com
[~abayer] This issue is affecting us also, if you can suggest a temporary work around that would help us Thanks

 

Restarting a stage from the original build will work, but restarting a stage twice does not work (restarting a failed restarted stage)

amleszk@gmail.com (JIRA)

unread,
Nov 2, 2019, 2:27:13 PM11/2/19
to jenkinsc...@googlegroups.com
[~abayer] This issue is affecting us also, if you can suggest a temporary work around that would help us Thanks

 

Restarting a stage from the original build will work, but restarting a stage twice does not work (restarting a failed restarted stage) .

 

We rely on environment variables instead of global variables

frankgenerated@gmail.com (JIRA)

unread,
Dec 6, 2019, 6:35:03 PM12/6/19
to jenkinsc...@googlegroups.com

Hello,

We're using a lot of classes in our pipeline libraries, and instead of passing the WorkflowScript in every single function, we are keeping a reference of that WorkflowScript in a Singleton in order to access Pipeline Functions from any of the classes. We are initializing that singleton at the beginning of our pipelines.

I just noticed that we are losing the reference on the WorkflowScript on restarts, so our Pipeline is failing on the next access to the WorkflowScript singleton...

Would it be somehow possible for us to reset that reference? Maybe adding some kind of configurable `onResume` callback where we could reset some of those global/singletons ourselves?

Thanks

Reply all
Reply to author
Forward
0 new messages