Skip to content
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

Is it possible to extract the edges in the dependency graph via groovy? #31

Closed
alok15ee opened this issue Dec 8, 2020 · 3 comments
Closed

Comments

@alok15ee
Copy link

alok15ee commented Dec 8, 2020

Hi,
I can't seem to find API's directly available through the Jenkins groovy Sandbox API's. I can always parse the JSON data but was wondering if there is a straightforward method to find upstream and downstream based on the graph.

Update: I found this https://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#getDependencyGraph-- but it doesn't support workflow projects.

@guidograzioli
Copy link
Member

Hello,
the method you found is what the depgraph-plugin uses internally to draw old-style build trigger dependencies (ie. the black arrows). Here is the relevant code: https://github.com/jenkinsci/depgraph-view-plugin/blob/master/src/main/java/hudson/plugins/depgraph_view/model/graph/edge/DependencyGraphEdgeProvider.java

In the groovy console, you can access the graph starting from a project, using this code:

import hudson.plugins.depgraph_view.model.graph.*;
import hudson.plugins.depgraph_view.model.graph.edge.*;
import static hudson.plugins.depgraph_view.model.graph.ProjectNode.node;
import com.google.common.collect.ImmutableSet;

def job = Jenkins.instance.items.find { it.name == "maven-pipeline-project2" }
ImmutableSet providers = ImmutableSet.<EdgeProvider>of(
      new DependencyGraphEdgeProvider(Jenkins.instance),
      new PipelineGraphPublisherEdgeProvider(Jenkins.instance));
DependencyGraph dg = new GraphCalculator(providers).generateGraph(Collections.singleton(node(job)));
println dg.getEdges();
println dg.getGraph().getVertices();

In the provider set you can "pick" edge provider types from here: https://github.com/jenkinsci/depgraph-view-plugin/tree/master/src/main/java/hudson/plugins/depgraph_view/model/graph/edge

@alok15ee
Copy link
Author

alok15ee commented Dec 21, 2020

@guidograzioli Thanks, this is what exactly I was looking for. Let me give it a try and I will reach out to you again.

@alok15ee
Copy link
Author

@guidograzioli It always gives me empty nodes and vertices for pipeline jobs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants