Search in sources :

Example 1 with FolderJob

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

the class ClassicJobApi method getFolder.

public FolderJob getFolder(Folder folder, boolean createMissing) throws IOException {
    if (folder == null || folder.getFolders().size() == 0) {
        return null;
    }
    Job job = jenkins.getJob(folder.get(0));
    if (job == null && createMissing) {
        createFolderImpl(null, folder.get(0));
        job = jenkins.getJob(folder.get(0));
    }
    FolderJob ret = jenkins.getFolderJob(job).get();
    for (int i = 1; i < folder.getFolders().size(); i++) {
        job = jenkins.getJob(ret, folder.get(i));
        if (job == null && createMissing) {
            createFolderImpl(ret, folder.get(i));
            job = jenkins.getJob(ret, folder.get(i));
        }
        ret = jenkins.getFolderJob(job).get();
    }
    return ret;
}
Also used : FolderJob(com.offbytwo.jenkins.model.FolderJob) Job(com.offbytwo.jenkins.model.Job) FolderJob(com.offbytwo.jenkins.model.FolderJob)

Example 2 with FolderJob

use of com.offbytwo.jenkins.model.FolderJob 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 3 with FolderJob

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

the class JenkinsAsserts method findJobPath.

/**
 * Tries to find a job via the given path
 */
public static JobWithDetails findJobPath(JenkinsServer jenkins, String... jobPath) throws IOException {
    FolderJob folder = null;
    for (int i = 0, size = jobPath.length; i < size; i++) {
        String path = jobPath[i];
        if (size == 1 && i == 0) {
            return jenkins.getJob(path);
        }
        if (folder == null) {
            JobWithDetails jobDetails = jenkins.getJob(path);
            if (jobDetails == null) {
                return null;
            }
            Job job = new Job(jobDetails.getName(), jobDetails.getUrl());
            Optional<FolderJob> optional = jenkins.getFolderJob(job);
            if (!optional.isPresent()) {
                return null;
            }
            folder = optional.get();
            continue;
        }
        Job job = folder.getJob(path);
        if (job == null) {
            return null;
        }
        if (i == size - 1) {
            return job.details();
        } else {
            Optional<FolderJob> optional = jenkins.getFolderJob(job);
            if (!optional.isPresent()) {
                return null;
            }
            folder = optional.get();
        }
    }
    return null;
}
Also used : JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails) FolderJob(com.offbytwo.jenkins.model.FolderJob) Job(com.offbytwo.jenkins.model.Job) FolderJob(com.offbytwo.jenkins.model.FolderJob)

Example 4 with FolderJob

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

the class ClassicJobApi method createFolders.

public void createFolders(Folder folder, boolean deleteRoot) throws IOException {
    if (deleteRoot) {
        jenkins.deleteJob(folder.get(0));
    }
    jenkins.createFolder(folder.get(0));
    FolderJob lastFolder = jenkins.getFolderJob(jenkins.getJob(folder.get(0))).get();
    for (int i = 1; i < folder.getFolders().size(); i++) {
        lastFolder.createFolder(folder.get(0));
        lastFolder = jenkins.getFolderJob(lastFolder.getJob(folder.get(0))).get();
    }
    ;
}
Also used : FolderJob(com.offbytwo.jenkins.model.FolderJob)

Example 5 with FolderJob

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

the class SearchTest method testSearch.

@Test
public void testSearch() throws InterruptedException, UnirestException, IOException {
    int totalJobs = 4;
    String alpha = "search-test-freestyle-alpha";
    String bravo = "search-test-freestyle-bravo";
    jobApi.createFreeStyleJob(alpha, "echo alpha");
    jobApi.createFreeStyleJob(bravo, "echo bravo");
    FolderJob jobFolder = jobApi.getFolder(Folder.folders("folder1", "folder2"), true);
    jobApi.createFreeStyleJob(jobFolder, "zz", "echo zz");
    jobApi.createFreeStyleJob(jobFolder, "zx", "echo zx");
    dashboardPage.open();
    dashboardPage.enterSearchText(alpha);
    dashboardPage.testJobCountEqualTo(1);
    dashboardPage.findJob(alpha);
    dashboardPage.clearSearchText();
    dashboardPage.testJobCountAtLeast(totalJobs);
    dashboardPage.enterSearchText("folder1/");
    dashboardPage.testJobCountEqualTo(2);
    dashboardPage.clearSearchText();
    dashboardPage.testJobCountAtLeast(totalJobs);
    dashboardPage.enterSearchText("f*/z*");
    dashboardPage.testJobCountEqualTo(2);
    dashboardPage.clearSearchText();
    dashboardPage.testJobCountAtLeast(totalJobs);
    dashboardPage.enterSearchText("z*");
    dashboardPage.testJobCountEqualTo(2);
    dashboardPage.clearSearchText();
    dashboardPage.testJobCountAtLeast(totalJobs);
    dashboardPage.enterSearchText("zz*");
    dashboardPage.testJobCountEqualTo(1);
    dashboardPage.clearSearchText();
    dashboardPage.testJobCountAtLeast(totalJobs);
    dashboardPage.enterSearchText("*search-test*");
    dashboardPage.testJobCountEqualTo(2);
    dashboardPage.clearSearchText();
    dashboardPage.testJobCountAtLeast(totalJobs);
}
Also used : FolderJob(com.offbytwo.jenkins.model.FolderJob) Test(org.junit.Test)

Aggregations

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