Search in sources :

Example 6 with Run

use of hudson.model.Run in project blueocean-plugin by jenkinsci.

the class ArtifactContainerImplTest method testArtifactsListing.

@Test
public void testArtifactsListing() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new Shell("#!/bin/bash\nmkdir -p test/me/out; cd test/me/out; touch {0..105}.txt"));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    List artifacts = request().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
    Assert.assertEquals(100, artifacts.size());
    Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size"));
    Assert.assertEquals("test/me/out/0.txt", ((Map) artifacts.get(0)).get("path"));
    Assert.assertEquals("/job/artifactTest/1/artifact/test/me/out/0.txt", ((Map) artifacts.get(0)).get("url"));
}
Also used : Shell(hudson.tasks.Shell) ArtifactArchiver(hudson.tasks.ArtifactArchiver) Run(hudson.model.Run) List(java.util.List) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 7 with Run

use of hudson.model.Run in project blueocean-plugin by jenkinsci.

the class BaseTest method validatePipeline.

protected void validatePipeline(Job p, Map resp) {
    Assert.assertEquals("jenkins", resp.get("organization"));
    Assert.assertEquals(p.getName(), resp.get("name"));
    Assert.assertEquals(p.getDisplayName(), resp.get("displayName"));
    Assert.assertEquals(p.getFullName(), resp.get("fullName"));
    Assert.assertEquals(p.getBuildHealth().getScore(), resp.get("weatherScore"));
    if (p.getLastSuccessfulBuild() != null) {
        Run b = p.getLastSuccessfulBuild();
        String s = baseUrl + "/organizations/jenkins/pipelines/" + p.getName() + "/runs/" + b.getId() + "/";
        Assert.assertEquals(s, resp.get("lastSuccessfulRun"));
    } else {
        Assert.assertNull(resp.get("lastSuccessfulRun"));
    }
    if (p.getLastBuild() != null) {
        Run r = p.getLastBuild();
        validateRun(r, (Map) resp.get("latestRun"), "FINISHED");
    } else {
        Assert.assertNull(resp.get("latestRun"));
    }
}
Also used : Run(hudson.model.Run)

Example 8 with Run

use of hudson.model.Run in project violations-plugin by jenkinsci.

the class AbstractViolationsBuildAction method doGraph.

/**
     * This corresponds to the url ./graph.
     *
     * @param req
     *            the request parameters.
     * @param rsp
     *            the response.
     * @throws IOException
     *             if there is an error writing the graph
     */
public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
    String type = req.getParameter("type");
    if (ChartUtil.awtProblemCause != null) {
        // not available. send out error message
        rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
        return;
    }
    getBuild().getTimestamp();
    if (!StringUtil.isBlank(type)) {
        ChartUtil.generateGraph(req, rsp, new SeverityTypeDataSet(getReport(), type).createChart(), X_SIZE, Y_SIZE);
        return;
    }
    DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> dsb = new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>();
    for (ViolationsReport r : ViolationsReport.iteration(getBuild())) {
        for (String ty : r.getViolations().keySet()) {
            dsb.add(roundUp(r.getViolations().get(ty)), ty, new ChartUtil.NumberOnlyBuildLabel((Run) r.getBuild()));
        }
    }
    ChartUtil.generateGraph(req, rsp, createChart(dsb.build()), X_SIZE, Y_SIZE);
}
Also used : ChartUtil(hudson.util.ChartUtil) DataSetBuilder(hudson.util.DataSetBuilder) ViolationsReport(hudson.plugins.violations.ViolationsReport) Run(hudson.model.Run) SeverityTypeDataSet(hudson.plugins.violations.graph.SeverityTypeDataSet)

Example 9 with Run

use of hudson.model.Run in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilder method getTryBlueOceanURLs.

/**
     * Get the {@link TryBlueOceanURLs} instance for the {@link ModelObject}
     * associated with the current Stapler request.
     *
     * @return The {@link TryBlueOceanURLs} instance for the current classic
     * Jenkins page. The URL to the Blue Ocean homepage is returned if a more
     * appropriate URL is not found.
     */
@Nonnull
public static TryBlueOceanURLs getTryBlueOceanURLs() {
    StaplerRequest staplerRequest = Stapler.getCurrentRequest();
    List<Ancestor> list = staplerRequest.getAncestors();
    // Blue Ocean page we can link onto.
    for (int i = list.size() - 1; i >= 0; i--) {
        Ancestor ancestor = list.get(i);
        Object object = ancestor.getObject();
        if (object instanceof ModelObject) {
            String blueUrl = toBlueOceanURL((ModelObject) object);
            if (blueUrl != null) {
                if (object instanceof Item) {
                    return new TryBlueOceanURLs(blueUrl, ((Item) object).getUrl());
                } else if (object instanceof Run) {
                    return new TryBlueOceanURLs(blueUrl, ((Run) object).getUrl());
                } else {
                    return new TryBlueOceanURLs(blueUrl);
                }
            } else if (object instanceof Item) {
                return new TryBlueOceanURLs(getBlueHome(), ((Item) object).getUrl());
            }
        }
    }
    // Otherwise just return Blue Ocean home.
    return new TryBlueOceanURLs(getBlueHome());
}
Also used : Item(hudson.model.Item) ModelObject(hudson.model.ModelObject) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ModelObject(hudson.model.ModelObject) Run(hudson.model.Run) Ancestor(org.kohsuke.stapler.Ancestor) Nonnull(javax.annotation.Nonnull)

Example 10 with Run

use of hudson.model.Run in project blueocean-plugin by jenkinsci.

the class PipelineBranchRunStatePreloader method getFetchData.

@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    //
    if (!blueUrl.hasPart(BlueUrlTokenizer.UrlPart.BRANCH) || !blueUrl.hasPart(BlueUrlTokenizer.UrlPart.PIPELINE_RUN_DETAIL_ID)) {
        // Not interested in it
        return null;
    }
    Jenkins jenkins = Jenkins.getInstance();
    String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
    String branchName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.BRANCH);
    String runId = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE_RUN_DETAIL_ID);
    Item pipelineJobItem = jenkins.getItemByFullName(pipelineFullName);
    if (pipelineJobItem instanceof MultiBranchProject) {
        try {
            MultiBranchProject pipelineMBP = (MultiBranchProject) pipelineJobItem;
            Job pipelineBranchJob = pipelineMBP.getItem(branchName);
            if (pipelineBranchJob != null) {
                Run run = pipelineBranchJob.getBuild(runId);
                if (run != null) {
                    BlueRun blueRun = AbstractRunImpl.getBlueRun(run, BluePipelineFactory.resolve(pipelineBranchJob));
                    if (blueRun != null) {
                        try {
                            return new FetchData(blueRun.getLink().getHref(), ModelObjectSerializer.toJson(blueRun));
                        } catch (IOException e) {
                            LOGGER.log(Level.FINE, String.format("Unable to preload run for pipeline '%s'. Run serialization error.", run.getUrl()), e);
                            return null;
                        }
                    } else {
                        LOGGER.log(Level.FINE, String.format("Unable to find run %s on branch named %s on pipeline named '%s'.", runId, branchName, pipelineFullName));
                        return null;
                    }
                }
            } else {
                LOGGER.log(Level.FINE, String.format("Unable to find branch named %s on pipeline named '%s'.", branchName, pipelineFullName));
                return null;
            }
        } catch (Exception e) {
            LOGGER.log(Level.FINE, String.format("Unable to find run from pipeline named '%s'.", pipelineFullName), e);
            return null;
        }
    } else {
        LOGGER.log(Level.FINE, String.format("Unable to find pipeline named '%s'.", pipelineFullName));
        return null;
    }
    // Don't preload any data on the page.
    return null;
}
Also used : Jenkins(jenkins.model.Jenkins) Item(hudson.model.Item) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) MultiBranchProject(jenkins.branch.MultiBranchProject) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) IOException(java.io.IOException) Job(hudson.model.Job) IOException(java.io.IOException)

Aggregations

Run (hudson.model.Run)26 FreeStyleProject (hudson.model.FreeStyleProject)5 Job (hudson.model.Job)5 Test (org.junit.Test)5 Item (hudson.model.Item)4 Shell (hudson.tasks.Shell)4 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)4 Map (java.util.Map)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 ArtifactArchiver (hudson.tasks.ArtifactArchiver)3 ArrayList (java.util.ArrayList)3 AbstractProject (hudson.model.AbstractProject)2 ViolationsReport (hudson.plugins.violations.ViolationsReport)2 DataSetBuilder (hudson.util.DataSetBuilder)2 IOException (java.io.IOException)2 Nonnull (javax.annotation.Nonnull)2 MultiBranchProject (jenkins.branch.MultiBranchProject)2 Jenkins (jenkins.model.Jenkins)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 Ancestor (org.kohsuke.stapler.Ancestor)2