Search in sources :

Example 1 with Build

use of com.offbytwo.jenkins.model.Build in project blueocean-plugin by jenkinsci.

the class ClassicJobApi method abortAllBuilds.

public void abortAllBuilds(Folder folder, String pipeline) throws IOException {
    JobWithDetails job = jenkins.getJob(getFolder(folder, false), pipeline);
    for (Build build : job.getBuilds()) {
        if (build.details().getResult() == null) {
            build.details().Stop();
            logger.info("Stopped build " + folder.getPath(pipeline) + " - #" + build.getNumber());
        }
    }
    Optional<FolderJob> folderJobOptional = jenkins.getFolderJob(job);
    if (folderJobOptional.isPresent()) {
        for (String s : folderJobOptional.get().getJobs().keySet()) {
            abortAllBuilds(folder.append(pipeline), s);
        }
    }
}
Also used : Build(com.offbytwo.jenkins.model.Build) JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails) FolderJob(com.offbytwo.jenkins.model.FolderJob)

Example 2 with Build

use of com.offbytwo.jenkins.model.Build 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)

Example 3 with Build

use of com.offbytwo.jenkins.model.Build in project fabric8 by fabric8io.

the class JenkinsAsserts method assertJobHasBuild.

public static Build assertJobHasBuild(JenkinsServer jenkins, String jobName) {
    JobWithDetails job = assertJobExists(jenkins, jobName);
    Build lastBuild = job.getLastBuild();
    assertNotNull("No lastBuild for job `" + jobName + "`", lastBuild);
    return lastBuild;
}
Also used : Build(com.offbytwo.jenkins.model.Build) JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails)

Aggregations

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