Search in sources :

Example 6 with JobWithDetails

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

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

the class JenkinsAsserts method assertWaitForJobPathExists.

/**
 * Waits for the given time period for the given job path to exist in Jenkins
 *
 * @return the job details
 */
public static JobWithDetails assertWaitForJobPathExists(final JenkinsServer jenkins, long timeMillis, String... jobPath) throws Exception {
    final AtomicReference<JobWithDetails> holder = new AtomicReference<>(null);
    LOG.info("Waiting for Jenkins job " + fullJobPath(jobPath));
    Asserts.assertWaitFor(timeMillis, new Block() {

        @Override
        public void invoke() throws Exception {
            holder.set(assertJobPathExists(jenkins, jobPath));
        }
    });
    return holder.get();
}
Also used : Block(io.fabric8.utils.Block) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 8 with JobWithDetails

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

the class JenkinsAsserts method assertTriggerJobPath.

/**
 * Asserts that we can trigger the job defined by the given path
 */
public static QueueReference assertTriggerJobPath(JenkinsServer jenkins, String... jobPath) throws IOException {
    JobWithDetails jobWithDetails = assertJobPathExists(jenkins, jobPath);
    QueueReference build = jobWithDetails.build(true);
    assertNotNull("No build reference for job " + fullJobPath(jobPath), build != null);
    return build;
}
Also used : QueueReference(com.offbytwo.jenkins.model.QueueReference) JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails)

Example 9 with JobWithDetails

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

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

the class JenkinsAsserts method assertJobPathExists.

/**
 * Asserts that a job exists with the given path
 */
public static JobWithDetails assertJobPathExists(JenkinsServer jenkins, String... jobPath) throws IOException {
    JobWithDetails job = findJobPath(jenkins, jobPath);
    assertNotNull("Could not find Jenkins Job: " + fullJobPath(jobPath), job);
    LOG.info("Found job " + job.getUrl());
    return job;
}
Also used : JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails)

Aggregations

JobWithDetails (com.offbytwo.jenkins.model.JobWithDetails)11 Build (com.offbytwo.jenkins.model.Build)3 FolderJob (com.offbytwo.jenkins.model.FolderJob)3 Job (com.offbytwo.jenkins.model.Job)3 BuildWithDetails (com.offbytwo.jenkins.model.BuildWithDetails)2 Properties (java.util.Properties)2 JenkinsServer (com.offbytwo.jenkins.JenkinsServer)1 Artifact (com.offbytwo.jenkins.model.Artifact)1 QueueReference (com.offbytwo.jenkins.model.QueueReference)1 Block (io.fabric8.utils.Block)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Git (org.eclipse.jgit.api.Git)1 Status (org.eclipse.jgit.api.Status)1 DirCache (org.eclipse.jgit.dircache.DirCache)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1