Search in sources :

Example 1 with NodeGraphBuilder

use of io.jenkins.blueocean.rest.impl.pipeline.NodeGraphBuilder in project blueocean-plugin by jenkinsci.

the class PipelinePluginAnalytics method onCompleted.

@Override
public void onCompleted(WorkflowRun workflowRun, @Nonnull TaskListener listener) {
    Analytics analytics = Analytics.get();
    if (analytics == null) {
        return;
    }
    // Tally up all the steps used in this run
    Tally tally = new Tally();
    NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(workflowRun);
    builder.getPipelineNodeSteps(new Link("steps/")).forEach(step -> {
        tally.count(step.getStepType());
    });
    boolean isDeclarative = workflowRun.getParent().getAction(DeclarativeJobAction.class) != null;
    Result result = workflowRun.getResult();
    String resultAsString = result != null ? result.toString() : "UNKNOWN";
    // Send event for each step used in this run
    tally.get().forEach((key, value) -> {
        ImmutableMap.Builder<String, Object> props = ImmutableMap.builder();
        props.put("type", key);
        props.put("timesUsed", value);
        props.put("isDeclarative", isDeclarative);
        props.put("runResult", resultAsString);
        analytics.track(new TrackRequest("pipeline_step_used", props.build()));
    });
}
Also used : Tally(io.jenkins.blueocean.service.embedded.analytics.Tally) TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) DeclarativeJobAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction) Analytics(io.jenkins.blueocean.analytics.Analytics) Link(io.jenkins.blueocean.rest.hal.Link) ImmutableMap(com.google.common.collect.ImmutableMap) NodeGraphBuilder(io.jenkins.blueocean.rest.impl.pipeline.NodeGraphBuilder) Result(hudson.model.Result)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Result (hudson.model.Result)1 Analytics (io.jenkins.blueocean.analytics.Analytics)1 TrackRequest (io.jenkins.blueocean.analytics.Analytics.TrackRequest)1 Link (io.jenkins.blueocean.rest.hal.Link)1 NodeGraphBuilder (io.jenkins.blueocean.rest.impl.pipeline.NodeGraphBuilder)1 Tally (io.jenkins.blueocean.service.embedded.analytics.Tally)1 DeclarativeJobAction (org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction)1