Skip to content

Delete DownstreamJobListener and instead create NodeDownstreamBuildAction dynamically during graph processing based on DownstreamBuildAction #2540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import hudson.model.InvisibleAction;
import io.jenkins.blueocean.rest.Reachable;
import io.jenkins.blueocean.rest.hal.Link;
import java.util.Objects;
import org.jenkinsci.plugins.workflow.actions.FlowNodeAction;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.util.Objects;

/**
* Annotates a FlowNode to point to a downstream build triggered by said node. Applied by
* io.jenkins.blueocean.listeners.DownstreamJobListener in blueocean-pipeline-api-impl
* Annotates a FlowNode to point to a downstream build triggered by said node.
* <p>Added dynamically to {@code FlowNodeWrapper} during graph processing by {@code PipelineNodeGraphVisitor}.
*/
@ExportedBean
public class NodeDownstreamBuildAction extends InvisibleAction implements FlowNodeAction, Reachable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.Action;
import hudson.model.Run;
import io.jenkins.blueocean.listeners.NodeDownstreamBuildAction;
import io.jenkins.blueocean.rest.hal.Link;
import io.jenkins.blueocean.rest.hal.LinkResolver;
import io.jenkins.blueocean.rest.model.BluePipelineNode;
import io.jenkins.blueocean.rest.model.BluePipelineStep;
import io.jenkins.blueocean.rest.model.BlueRun;
Expand All @@ -28,6 +31,7 @@
import org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming;
import org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo;
import org.jenkinsci.plugins.workflow.support.actions.PauseAction;
import org.jenkinsci.plugins.workflow.support.steps.build.DownstreamBuildAction;
import org.jenkinsci.plugins.workflow.support.steps.input.InputAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -97,6 +101,8 @@ public class PipelineNodeGraphVisitor extends StandardChunkVisitor implements No

// Collects instances of Action as we walk up the graph, to be drained when appropriate
private Set<Action> pipelineActions;
// The IDs of nodes which contributed to pipelineActions.
private Set<String> pipelineActionsNodes;

// Temporary holding for actions waiting to be assigned to the wrapper for a branch
private Map<FlowNode /* is the branchStartNode */, Set<Action>> pendingActionsForBranches;
Expand Down Expand Up @@ -558,6 +564,7 @@ private void dump(String str) {
protected void accumulatePipelineActions(FlowNode node) {
final List<Action> actions = node.getActions(Action.class);
pipelineActions.addAll(actions);
pipelineActionsNodes.add(node.getId());
if (isNodeVisitorDumpEnabled) {
dump(String.format("\t\taccumulating actions - added %d, total is %d", actions.size(), pipelineActions.size()));
}
Expand All @@ -571,12 +578,29 @@ protected Set<Action> drainPipelineActions() {
dump(String.format("\t\tdraining accumulated actions - total is %d", pipelineActions.size()));
}

if (pipelineActions.size() == 0) {
return Collections.emptySet();
}

Set<Action> drainedActions = pipelineActions;
Set<String> nodes = pipelineActionsNodes;
pipelineActions = new HashSet<>();
pipelineActionsNodes = new HashSet<>();
if (!nodes.isEmpty()) {
DownstreamBuildAction action = run.getAction(DownstreamBuildAction.class);
if (action != null) {
for (DownstreamBuildAction.DownstreamBuild downstreamBuild : action.getDownstreamBuilds()) {
if (nodes.contains(downstreamBuild.getFlowNodeId())) {
Run<?, ?> downstream = downstreamBuild.getBuild();
if (downstream != null) {
Link link = LinkResolver.resolveLink(downstream);
String description = downstream.getDescription();
if (description == null) {
description = downstream.getFullDisplayName();
}
drainedActions.add(new NodeDownstreamBuildAction(link, description));
}
}
}
}
}

return drainedActions;
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.401.x</artifactId>
<version>2401.v7a_d68f8d0b_09</version>
<version>2661.vb_b_60650f6d97</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down