use of com.offbytwo.jenkins.model.BuildWithDetails in project gogs-webhook-plugin by jenkinsci.
the class GogsWebHook_IT method loadMarkerArtifactAsProperty.
/**
* 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 uunexpected went wrong loading the marker as a property
*/
private Properties loadMarkerArtifactAsProperty(JenkinsServer jenkins) throws IOException, URISyntaxException {
JobWithDetails detailedJob = jenkins.getJob(JENKINS_JOB_NAME);
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;
}
use of com.offbytwo.jenkins.model.BuildWithDetails in project fabric8 by fabric8io.
the class JenkinsAsserts method displayJobs.
public static void displayJobs(JenkinsServer jenkins, Map<String, Job> jobs, String indent) throws IOException {
Set<Map.Entry<String, Job>> entries = jobs.entrySet();
for (Map.Entry<String, Job> entry : entries) {
String jobName = entry.getKey();
Job job = entry.getValue();
String suffix = "";
JobWithDetails details = job.details();
if (details != null) {
Build lastBuild = details.getLastBuild();
if (lastBuild != null) {
BuildWithDetails buildDetails = lastBuild.details();
if (buildDetails != null) {
String buildId = buildDetails.getId();
if (buildId != null) {
suffix = ": #" + buildId;
}
}
}
}
System.out.println(indent + jobName + suffix);
Optional<FolderJob> optional = jenkins.getFolderJob(job);
if (optional.isPresent()) {
FolderJob folderJob = optional.get();
Map<String, Job> children = folderJob.getJobs();
displayJobs(jenkins, children, indent + INDENT);
}
}
}
Aggregations