Java Code Examples for org.jenkinsci.plugins.workflow.job.WorkflowRun#getResult()

The following examples show how to use org.jenkinsci.plugins.workflow.job.WorkflowRun#getResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PipelineNodeContainerImpl.java    From blueocean-plugin with MIT License 6 votes vote down vote up
public PipelineNodeContainerImpl(WorkflowRun run, Link parentLink) {
    this.run = run;
    this.self = parentLink.rel("nodes");

    WorkflowJob job = run.getParent();
    NodeGraphBuilder graphBuilder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run);

    //If build either failed or is in progress then return union with last successful pipeline run
    if (run.getResult() != Result.SUCCESS
        && job.getLastSuccessfulBuild() != null
        && Integer.parseInt(job.getLastSuccessfulBuild().getId()) < Integer.parseInt(run.getId())) {

        NodeGraphBuilder pastBuildGraph = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(job.getLastSuccessfulBuild());
        this.nodes = graphBuilder.union(pastBuildGraph.getPipelineNodes(), getLink());
    } else {
        this.nodes = graphBuilder.getPipelineNodes(getLink());
    }
    for (BluePipelineNode node : nodes) {
        nodeMap.put(node.getId(), node);
    }
}
 
Example 2
Source File: PipelinePluginAnalytics.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@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()));
    });
}
 
Example 3
Source File: DatabaseSyncRunListener.java    From pipeline-maven-plugin with MIT License 6 votes vote down vote up
@Override
public void onCompleted(WorkflowRun workflowRun, @Nonnull TaskListener listener) {
    super.onCompleted(workflowRun, listener);

    // Note: run.duration is zero in onCompleted(), do the substraction in this listener
    Result result = workflowRun.getResult();
    if (result == null) {
        result = Result.SUCCESS; // FIXME more elegant handling
    }
    globalPipelineMavenConfig.getDao().updateBuildOnCompletion(
            workflowRun.getParent().getFullName(),
            workflowRun.getNumber(),
            result.ordinal,
            workflowRun.getStartTimeInMillis(),
             Math.max(System.currentTimeMillis() - workflowRun.getStartTimeInMillis(), 0)); // @see HUDSON-5844
}
 
Example 4
Source File: BuildCulpritsWorkflowRun.java    From jenkins-build-monitor-plugin with MIT License 6 votes vote down vote up
@Override
public Set<String> getCulprits(Run<?, ?> run) {
    WorkflowRun workflowRun = (WorkflowRun) run;
    Set<String> culprits = new TreeSet<String>();
    //Workaround while waiting for https://issues.jenkins-ci.org/browse/JENKINS-24141
    WorkflowRun previous = workflowRun.getPreviousCompletedBuild();
    if (workflowRun.isBuilding()) {
        //We are currently building so add culprits from previous build (if any)
        if (previous != null) {
            Result previousResult = previous.getResult();
            if (previousResult != null && previousResult.isWorseThan(Result.SUCCESS)) {
                culprits.addAll(getCommitters(previous));
            }
        }
    }
    culprits.addAll(getCommitters(workflowRun));

    //Get culprits from earlier builds
    if (previous != null && previous.getPreviousNotFailedBuild() != null) {
        culprits.addAll(getCulpritsForRun(previous.getPreviousNotFailedBuild(), previous));
    }
    return culprits;
}
 
Example 5
Source File: PipelineNodeTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
private static int countBuilds(WorkflowJob job, Result status) {
    RunList<WorkflowRun> builds = job.getNewBuilds();
    Iterator<WorkflowRun> iterator = builds.iterator();
    int numBuilds = 0;

    while (iterator.hasNext()) {
        WorkflowRun build = iterator.next();
        Result buildRes = build.getResult();
        if (status == null || buildRes == status) {
            numBuilds++;
        }
    }

    return numBuilds;
}
 
Example 6
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void getPipelineJobAbortTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");

    job1.setDefinition(new CpsFlowDefinition("" +
        "node {" +
        "   stage ('Build1'); " +
        "   sleep(120);" +
        "   stage ('Test1'); " +
        "   echo ('Testing'); " +
        "}"));

    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    // Give the job some time to really start (allocate nodes and so on)
    Thread.sleep(5000);
    for (int i = 0; i < 10; i++) {
        b1.doStop();
        if (b1.getResult() != null) {
            break;
        }
        Thread.sleep(1000);
    }
    j.assertBuildStatus(Result.ABORTED, b1);

    Map r = get("/organizations/jenkins/pipelines/pipeline1/runs/1");

    validateRun(b1, r);
}