diff --git a/pom.xml b/pom.xml index 711c9d72a..d8276914d 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ io.jenkins.tools.bom bom-2.332.x - 1289.v5c4b_1c43511b_ + 1382.v7d694476f340 import pom @@ -89,6 +89,7 @@ org.jenkins-ci.plugins.workflow workflow-api + 1162.va_1e49062a_00e org.jenkins-ci.plugins.workflow diff --git a/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java b/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java index 18c43ad30..da5ef8c52 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java @@ -277,6 +277,13 @@ public class CpsFlowExecution extends FlowExecution implements BlockableResume { boolean resumeBlocked = false; + /** + * Whether {@link CpsThreadGroup#isPaused} when loaded from disk. + * @see #loadProgramAsync + * @see #afterStepExecutionsResumed + */ + private transient boolean pausedWhenLoaded; + /** Subdirectory string where we store {@link FlowNode}s */ private String storageDir = null; @@ -775,17 +782,8 @@ public void onSuccess(Unmarshaller u) { try { CpsThreadGroup g = (CpsThreadGroup) u.readObject(); result.set(g); - try { - if (g.isPaused()) { - owner.getListener().getLogger().println("Still paused"); - } else { - owner.getListener().getLogger().println("Ready to run at " + new Date()); - // In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart. - g.scheduleRun(); - } - } catch (IOException x) { - LOGGER.log(Level.WARNING, null, x); - } + pausedWhenLoaded = g.isPaused(); + g.pause(); } catch (Throwable t) { onFailure(t); } finally { @@ -871,6 +869,28 @@ void croak(Throwable t) { } } + @Override protected void afterStepExecutionsResumed() { + runInCpsVmThread(new FutureCallback() { + @Override public void onSuccess(CpsThreadGroup g) { + try { + if (pausedWhenLoaded) { + owner.getListener().getLogger().println("Still paused"); + } else { + owner.getListener().getLogger().println("Ready to run at " + new Date()); + // In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart. + g.unpause(); + g.saveProgramIfPossible(false); // ensure pausedWhenLoaded=false is persisted + } + } catch (IOException x) { + LOGGER.log(Level.WARNING, null, x); + } + } + @Override public void onFailure(Throwable t) { + LOGGER.log(Level.WARNING, "could not resume " + this, t); + } + }); + } + /** * Where we store {@link CpsThreadGroup}. */