Search in sources :

Example 1 with BuildUpstreamNodeAction

use of org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamNodeAction in project blueocean-plugin by jenkinsci.

the class DownstreamJobListener method onStarted.

@Override
public void onStarted(Run<?, ?> run, TaskListener listener) {
    for (BuildUpstreamNodeAction action : run.getActions(BuildUpstreamNodeAction.class)) {
        Run triggerRun = Run.fromExternalizableId(action.getUpstreamRunId());
        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(action.getUpstreamNodeId());
            } 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);
                }
            }
        }
    }
}
Also used : FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Run(hudson.model.Run) IOException(java.io.IOException) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) BuildUpstreamNodeAction(org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamNodeAction) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Aggregations

Run (hudson.model.Run)1 Link (io.jenkins.blueocean.rest.hal.Link)1 IOException (java.io.IOException)1 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 BuildUpstreamNodeAction (org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamNodeAction)1