@@ -277,6 +277,13 @@ public class CpsFlowExecution extends FlowExecution implements BlockableResume {
277277
278278 boolean resumeBlocked = false ;
279279
280+ /**
281+ * Whether {@link CpsThreadGroup#isPaused} when loaded from disk.
282+ * @see #loadProgramAsync
283+ * @see #afterStepExecutionsResumed
284+ */
285+ private transient boolean pausedWhenLoaded ;
286+
280287 /** Subdirectory string where we store {@link FlowNode}s */
281288 private String storageDir = null ;
282289
@@ -775,17 +782,8 @@ public void onSuccess(Unmarshaller u) {
775782 try {
776783 CpsThreadGroup g = (CpsThreadGroup ) u .readObject ();
777784 result .set (g );
778- try {
779- if (g .isPaused ()) {
780- owner .getListener ().getLogger ().println ("Still paused" );
781- } else {
782- owner .getListener ().getLogger ().println ("Ready to run at " + new Date ());
783- // In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
784- g .scheduleRun ();
785- }
786- } catch (IOException x ) {
787- LOGGER .log (Level .WARNING , null , x );
788- }
785+ pausedWhenLoaded = g .isPaused ();
786+ g .pause ();
789787 } catch (Throwable t ) {
790788 onFailure (t );
791789 } finally {
@@ -871,6 +869,28 @@ void croak(Throwable t) {
871869 }
872870 }
873871
872+ @ Override protected void afterStepExecutionsResumed () {
873+ runInCpsVmThread (new FutureCallback <CpsThreadGroup >() {
874+ @ Override public void onSuccess (CpsThreadGroup g ) {
875+ try {
876+ if (pausedWhenLoaded ) {
877+ owner .getListener ().getLogger ().println ("Still paused" );
878+ } else {
879+ owner .getListener ().getLogger ().println ("Ready to run at " + new Date ());
880+ // In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
881+ g .unpause ();
882+ g .saveProgramIfPossible (false ); // ensure pausedWhenLoaded=false is persisted
883+ }
884+ } catch (IOException x ) {
885+ LOGGER .log (Level .WARNING , null , x );
886+ }
887+ }
888+ @ Override public void onFailure (Throwable t ) {
889+ LOGGER .log (Level .WARNING , "could not resume " + this , t );
890+ }
891+ });
892+ }
893+
874894 /**
875895 * Where we store {@link CpsThreadGroup}.
876896 */
0 commit comments