use of org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause in project blueocean-plugin by jenkinsci.
the class DownstreamJobListener method onStarted.
@Override
public void onStarted(Run<?, ?> run, TaskListener listener) {
for (Cause cause : run.getCauses()) {
if (cause instanceof BuildUpstreamCause) {
BuildUpstreamCause buildUpstreamCause = (BuildUpstreamCause) cause;
Run triggerRun = buildUpstreamCause.getUpstreamRun();
if (triggerRun instanceof WorkflowRun) {
FlowExecution execution = ((WorkflowRun) triggerRun).getExecution();
FlowNode node;
if (execution == null) {
LOGGER.warning("Could not retrieve upstream FlowExecution");
continue;
}
try {
node = execution.getNode(buildUpstreamCause.getNodeId());
} catch (IOException e) {
LOGGER.warning("Could not retrieve upstream node: " + e);
continue;
}
if (node == null) {
LOGGER.warning("Could not retrieve upstream node (null)");
continue;
}
// Add an action on the triggerRun node pointing to the currently executing run
String description = run.getDescription();
if (description == null) {
description = run.getFullDisplayName();
}
Link link = LinkResolver.resolveLink(run);
if (link != null) {
try {
// Also add to the actual trigger node so we can find it later by step
node.addAction(new NodeDownstreamBuildAction(link, description));
node.save();
} catch (IOException e) {
LOGGER.severe("Could not persist node: " + e);
}
}
}
}
}
}
Aggregations