com.offbytwo.jenkins.model.BuildWithDetails Java Examples

The following examples show how to use com.offbytwo.jenkins.model.BuildWithDetails. 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: BuildHistory.java    From seppb with MIT License 5 votes vote down vote up
public static BuildHistory apply(Integer number, BuildWithDetails details, String jobName) {
	return BuildHistory.builder()
			.buildStatus(buildToBuildStatus(details))
			.buildVersion(number)
			.jobName(jobName)
			.codeChange(codeChange(details.getChangeSets()))
			.buildInterval(details.getDuration())
			.build();
}
 
Example #2
Source File: JenkinsStatusUpdater.java    From seppb with MIT License 5 votes vote down vote up
private void updateBuild(String jobName, JenkinsClient jenkinsClient, Build build) throws IOException {
	PipelineStep pipelineStep = jenkinsClient.pipelineStep(jobName, build.getNumber());
	BuildWithDetails details = build.details();
	BuildHistory buildHistory = apply(build.getNumber(), details, jobName);
	String pipeline = mapper.writeValueAsString(pipelineStep);
	buildHistory.setPipelineStep(pipeline);
	buildHistoryService.createOrUpdate(buildHistory);
	deploymentStatusUpdater.updateDeploymentResult(DeploymentHistory.builder()
			.jobName(jobName)
			.deployStatus(convertJenkinsStatus(details))
			.buildVersion(build.getNumber())
			.pipelineStep(pipeline)
			.deployJobName(DEPLOY_JOB_NAME).build());
}
 
Example #3
Source File: DeploymentService.java    From seppb with MIT License 5 votes vote down vote up
private JenkinsBuildResp buildJenkinsBuildResp(Build build) {
	BuildWithDetails details;
	try {
		details = build.details();
	} catch (IOException e) {
		throw new SeppClientException("无法该job可以部署的版本");
	}
	return JenkinsBuildResp.apply(build.getNumber(), details.getResult());
}
 
Example #4
Source File: GogsWebHook_IT.java    From gogs-webhook-plugin with MIT License 5 votes vote down vote up
/**
 * Loads the marker file of the last build (archived during the build)
 *
 * @param jenkins the jenkins instance we want to load from
 * @return the marker file loaded as a property file (so that it can be easily queried)
 * @throws IOException        Something unexpected went wrong when querying the Jenkins server
 * @throws URISyntaxException Something unexpected went wrong loading the marker as a property
 */
private Properties loadMarkerArtifactAsProperty(JenkinsServer jenkins, String jobName) throws IOException, URISyntaxException {
    JobWithDetails detailedJob = jenkins.getJob(jobName);
    BuildWithDetails lastBuild = detailedJob.getLastBuild().details();
    int buildNbr = lastBuild.getNumber();
    boolean isBuilding = lastBuild.isBuilding();
    log.info("BuildNbr we are examining: " + buildNbr);

    List<Artifact> artifactList = lastBuild.getArtifacts();
    assertEquals("Not the expected number of artifacts", 1, artifactList.size());

    Artifact markerArtifact = artifactList.get(0);
    String markerArtifactFileName = markerArtifact.getFileName();
    assertEquals("The artifact is not the expected one", "marker.txt", markerArtifactFileName);
    InputStream markerArtifactInputStream = lastBuild.details().downloadArtifact(markerArtifact);
    String markerAsText = IOUtils.toString(markerArtifactInputStream, Charset.defaultCharset());
    log.info("\n" + markerAsText);
    StringReader reader = new StringReader(markerAsText);
    Properties markerAsProperty = new Properties();
    markerAsProperty.load(reader);

    //check if the marker matches the build number we expect.
    String buildNbrFromMarker = markerAsProperty.getProperty("BUILD_NUMBER");
    String buildNbrFromQery = String.valueOf(buildNbr);
    assertEquals("The build number from the marker does not match the last build number", buildNbrFromMarker, buildNbrFromQery);
    return markerAsProperty;
}
 
Example #5
Source File: JenkinsServerIntegration.java    From verigreen with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnBuildStatusForBuild() throws Exception {
    JobWithDetails job = server.getJobs().get("pr").details();
    BuildWithDetails build = job.getBuilds().get(0).details();
    assertEquals(BuildResult.SUCCESS, build.getResult());
    assertEquals("foobar", build.getParameters().get("REVISION"));
}