Skip to content

Commit

Permalink
Merge pull request #826 from dwnusbaum/save-flownode-actions-complete…
Browse files Browse the repository at this point in the history
…d-build

Throw an exception when trying to save actions for a `FlowNode` for a completed execution
  • Loading branch information
jglick authored Jan 9, 2024
2 parents c43e04d + 5507e1a commit c2a8f91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,8 @@ public List<Action> loadActions(FlowNode node) throws IOException {
public void saveActions(FlowNode node, List<Action> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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()));
});
}

}

0 comments on commit c2a8f91

Please sign in to comment.