diff --git a/pom.xml b/pom.xml index 689f1c7b..44c44a60 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,7 @@ org.jenkins-ci.plugins.workflow workflow-api + 1108.v57edf648f5d4 org.jenkins-ci.plugins.workflow diff --git a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java index 77fb8e6f..8710bc4e 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepExecution.java @@ -64,6 +64,7 @@ import org.jenkinsci.plugins.workflow.actions.QueueItemAction; import org.jenkinsci.plugins.workflow.actions.ThreadNameAction; 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.graph.FlowNode; import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl; @@ -422,11 +423,14 @@ public String getCookie() { } @Override public CauseOfBlockage getCauseOfBlockage() { - Run run = runForDisplay(); - if (!stopping && run != null && !run.isLogUpdated()) { - stopping = true; - LOGGER.warning(() -> "Refusing to build " + this + " and cancelling it because associated build is complete"); - Timer.get().execute(() -> Queue.getInstance().cancel(this)); + if (FlowExecutionList.get().isResumptionComplete()) { + // We only do this if resumption is complete so that we do not load the run and resume its execution in this context in normal scenarios. + Run run = runForDisplay(); + if (!stopping && run != null && !run.isLogUpdated()) { + stopping = true; + LOGGER.warning(() -> "Refusing to build " + this + " and cancelling it because associated build is complete"); + Timer.get().execute(() -> Queue.getInstance().cancel(this)); + } } if (stopping) { return new CauseOfBlockage() { diff --git a/src/test/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepTest.java b/src/test/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepTest.java index e7269c84..a38276f6 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepTest.java @@ -1299,6 +1299,7 @@ public void accessPermittedOnlyFromCurrentBuild() throws Throwable { WorkflowRun b = p.getBuildByNumber(1); assertFalse(b.isLogUpdated()); r.assertBuildStatusSuccess(b); + Queue.getInstance().maintain(); // Otherwise we may have to wait up to 5 seconds. while (Queue.getInstance().getItems().length > 0) { Thread.sleep(100L); }