Search in sources :

Example 1 with BuildWithDetails

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;
}
Also used : BuildWithDetails(com.offbytwo.jenkins.model.BuildWithDetails) JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails) Properties(java.util.Properties) Artifact(com.offbytwo.jenkins.model.Artifact)

Example 2 with BuildWithDetails

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);
        }
    }
}
Also used : BuildWithDetails(com.offbytwo.jenkins.model.BuildWithDetails) Build(com.offbytwo.jenkins.model.Build) FolderJob(com.offbytwo.jenkins.model.FolderJob) Job(com.offbytwo.jenkins.model.Job) JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails) Map(java.util.Map) FolderJob(com.offbytwo.jenkins.model.FolderJob)

Aggregations

BuildWithDetails (com.offbytwo.jenkins.model.BuildWithDetails)2 JobWithDetails (com.offbytwo.jenkins.model.JobWithDetails)2 Artifact (com.offbytwo.jenkins.model.Artifact)1 Build (com.offbytwo.jenkins.model.Build)1 FolderJob (com.offbytwo.jenkins.model.FolderJob)1 Job (com.offbytwo.jenkins.model.Job)1 Map (java.util.Map)1 Properties (java.util.Properties)1