Search in sources :

Example 1 with BuildUpstreamCause

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);
                    }
                }
            }
        }
    }
}
Also used : Cause(hudson.model.Cause) BuildUpstreamCause(org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) IOException(java.io.IOException) BuildUpstreamCause(org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Aggregations

Cause (hudson.model.Cause)1 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 BuildUpstreamCause (org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause)1