@Issue("JENKINS-52189")
@Test
public void notifyFlowStartNodeViaFlowExecutionListener() {
story.then(s->{
WorkflowJob j = jenkins().createProject(WorkflowJob.class, "bob");
j.setDefinition(new CpsFlowDefinition("echo 'I did a thing'", true));
WorkflowRun r = story.j.buildAndAssertSuccess(j);
FlowStartNodeFlowExectionListener listener = jenkins().getExtensionList(
FlowStartNodeFlowExectionListener.class).get(0);
assertThat(listener.heads, Matchers.greaterThan(1));
assertThat(listener.execNames, Matchers.contains(r.getExecution().toString()));
});
}
@TestExtension("notifyFlowStartNodeViaFlowExecutionListener")
public static class FlowStartNodeFlowExectionListener extends FlowExecutionListener {
int heads = 0;
final List<String> execNames = new ArrayList<>();
@Override
public void onRunning(@Nonnull FlowExecution execution) {
execution.addListener(node -> {
heads++;
if (node instanceof FlowStartNode) {
execNames.add(node.getExecution().toString());
}
});
}
}
PR with fix + test.