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"));
}
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"));
}
}
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);
}
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());
}
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;
}
Aggregations