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;
}
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();
}
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;
}
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);
}
}
}
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;
}
Aggregations