Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from pskumar448/master
JENKINS-32499 BuildGraph doesn't show up if there is a null run
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/jenkinsci/plugins/buildgraphview/FlowDownStreamRunDeclarer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
package org.jenkinsci.plugins.buildgraphview; | |||
|
|||
import com.cloudbees.plugins.flow.FlowCause; | |||
import com.cloudbees.plugins.flow.FlowRun; | |||
import com.cloudbees.plugins.flow.JobInvocation; | |||
import hudson.Extension; | |||
import hudson.model.Run; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Set; | |||
import java.util.concurrent.ExecutionException; | |||
|
|||
/** | |||
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a> | |||
*/ | |||
@Extension(optional = true) | |||
public class FlowDownStreamRunDeclarer extends DownStreamRunDeclarer { | |||
|
|||
@Override | |||
public List<Run> getDownStream(Run r) throws ExecutionException, InterruptedException { | |||
|
|||
if (r instanceof FlowRun) { | |||
FlowRun f = (FlowRun) r; | |||
return getOutgoingEdgeRuns(f, f.getStartJob()); | |||
} | |||
|
|||
List<Run> runs = Collections.emptyList(); | |||
FlowCause cause = (FlowCause) r.getCause(FlowCause.class); | |||
FlowRun f; | |||
while (runs.isEmpty() && cause != null) { | |||
f = cause.getFlowRun(); | |||
runs = getOutgoingEdgeRuns(f, cause.getAssociatedJob()); | |||
cause = (FlowCause) cause.getFlowRun().getCause(FlowCause.class); | |||
} | |||
|
|||
return runs; | |||
} | |||
|
|||
private List<Run> getOutgoingEdgeRuns(FlowRun f, JobInvocation start) throws ExecutionException, InterruptedException { | |||
Set<FlowRun.JobEdge> edges = f.getJobsGraph().outgoingEdgesOf(start); | |||
List<Run> runs = new ArrayList<Run>(edges.size()); | |||
for (FlowRun.JobEdge edge : edges) { | |||
JobInvocation targetJobEdge = edge.getTarget(); | |||
Run run = targetJobEdge.getBuild(); | |||
if (run != null) { | |||
runs.add(run); | |||
} | |||
} | |||
return runs; | |||
} | |||
} |
f1f892f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pskumar448 Than you make build-flow-plugin 0.19 a mandatory dependency?
FlowRun from build-flow-plugin is needed. See: https://issues.jenkins-ci.org/browse/JENKINS-34803
f1f892f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodrigc
Today me too faced issue after upgrading to newer version. I am updating and immediately will release patch for this