diff --git a/plugin/pom.xml b/plugin/pom.xml index a1ab7b669..4c79749ee 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -55,6 +55,12 @@ import pom + + + org.jenkins-ci.plugins.workflow + workflow-api + 1259.vb_47f14fffc8a_ + diff --git a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java index c993d3c5a..05431d838 100644 --- a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java +++ b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java @@ -1619,7 +1619,8 @@ public void pause(final boolean v) throws IOException { } @Restricted(DoNotUse.class) - @Terminator public static void suspendAll() { + @Terminator(attains = FlowExecutionList.EXECUTIONS_SUSPENDED) + public static void suspendAll() { CpsFlowExecution exec = null; try (Timeout t = Timeout.limit(3, TimeUnit.MINUTES)) { // TODO some complicated sequence of calls to Futures could allow all of them to run in parallel LOGGER.fine("starting to suspend all executions"); @@ -2164,10 +2165,4 @@ private void checkAndAbortNonresumableBuild() { } } - /** Ensures that even if we're limiting persistence of data for performance, we still write out data for shutdown. */ - @Override - protected void notifyShutdown() { - // No-op, handled in the suspendAll terminator - } - } diff --git a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java index ca20b6ec8..b82e0cc21 100644 --- a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java +++ b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java @@ -58,6 +58,7 @@ import jenkins.model.Jenkins; import org.apache.commons.io.FileUtils; import org.hamcrest.Matchers; +import static org.hamcrest.Matchers.containsInRelativeOrder; import org.htmlunit.ElementNotFoundException; import org.htmlunit.FailingHttpStatusCodeException; import org.htmlunit.HttpMethod; @@ -66,6 +67,7 @@ import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; import org.jenkinsci.plugins.workflow.cps.GroovySourceFileAllowlist.DefaultAllowlist; import org.jenkinsci.plugins.workflow.flow.FlowExecution; +import org.jenkinsci.plugins.workflow.flow.FlowExecutionList; import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; @@ -622,4 +624,16 @@ public boolean isAllowed(String groovyResourceUrl) { assertThat(EnvActionImpl.forRun(b).getEnvironment().get("foo"), equalTo("bar")); }); } + + @Test public void suspendOrder() throws Throwable { + System.setProperty(Jenkins.class.getName() + "." + "termLogLevel", "INFO"); + logger.record(CpsFlowExecution.class, Level.FINE).record(FlowExecutionList.class, Level.FINE).capture(100); + sessions.then(r -> { + WorkflowJob p = r.createProject(WorkflowJob.class); + p.setDefinition(new CpsFlowDefinition("echo 'ok'", true)); + r.buildAndAssertSuccess(p); + }); + assertThat(logger.getMessages(), containsInRelativeOrder("finished suspending all executions", "ensuring all executions are saved")); + } + }