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 683eecdf9..181471b5a 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 @@ -1276,6 +1276,8 @@ public List loadActions(FlowNode node) throws IOException { public void saveActions(FlowNode node, List actions) throws IOException { if (storage == null) { throw new IOException("storage not yet loaded"); + } else if (isComplete()) { + throw new IOException("Cannot save actions for " + node + " for completed execution " + this + ": " + actions); } storage.saveActions(node, actions); } 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 325ec7d83..f6687b930 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 @@ -33,6 +33,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -49,6 +50,7 @@ import hudson.model.Result; import hudson.model.TaskListener; import java.io.File; +import java.io.IOException; import java.io.Serializable; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -914,4 +916,15 @@ public boolean takesImplicitBlockArgument() { }); } + @Test public void flowNodesCantBeSavedAfterExecutionCompletes() throws Throwable { + sessions.then(r -> { + WorkflowJob p = r.createProject(WorkflowJob.class, "p"); + p.setDefinition(new CpsFlowDefinition("echo 'Hello, world!'", true)); + WorkflowRun b = r.buildAndAssertSuccess(p); + FlowNode echoStep = b.getExecution().getNode("3"); + IOException e = assertThrows(IOException.class, echoStep::save); + assertThat(e.getMessage(), containsString("Cannot save actions for " + echoStep + " for completed execution " + b.getExecution())); + }); + } + }