use of com.offbytwo.jenkins.model.Job in project stashbot by palantir.
the class JenkinsManager method createJob.
public void createJob(Repository repo, JobTemplate jobTemplate) {
try {
final RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
final JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
final JenkinsServer jenkinsServer = jenkinsClientManager.getJenkinsServer(jsc, rc);
final String jobName = jobTemplate.getBuildNameFor(repo);
// If we try to create a job which already exists, we still get a
// 200... so we should check first to make
// sure it doesn't already exist
Map<String, Job> jobMap = jenkinsServer.getJobs();
if (jobMap.containsKey(jobName)) {
throw new IllegalArgumentException("Job " + jobName + " already exists");
}
String xml = xmlFormatter.generateJobXml(jobTemplate, repo);
log.trace("Sending XML to jenkins to create job: " + xml);
jenkinsServer.createJob(jobName, xml);
} catch (IOException e) {
// TODO: something other than just rethrow?
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of com.offbytwo.jenkins.model.Job in project stashbot by palantir.
the class JenkinsManager method updateJob.
/**
* This method IGNORES the current job XML, and regenerates it from scratch, and posts it. If any changes were made
* to the job directly via jenkins UI, this will overwrite those changes.
*
* @param repo
* @param buildType
*/
public void updateJob(Repository repo, JobTemplate jobTemplate) {
try {
final RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
final JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
final JenkinsServer jenkinsServer = jenkinsClientManager.getJenkinsServer(jsc, rc);
final String jobName = jobTemplate.getBuildNameFor(repo);
// If we try to create a job which already exists, we still get a
// 200... so we should check first to make
// sure it doesn't already exist
Map<String, Job> jobMap = jenkinsServer.getJobs();
String xml = xmlFormatter.generateJobXml(jobTemplate, repo);
if (jobMap.containsKey(jobName)) {
if (!rc.getPreserveJenkinsJobConfig()) {
log.trace("Sending XML to jenkins to update job: " + xml);
jenkinsServer.updateJob(jobName, xml);
} else {
log.trace("Skipping sending XML to jenkins. Repo Config is set to preserve jenkins job config.");
}
return;
}
log.trace("Sending XML to jenkins to create job: " + xml);
jenkinsServer.createJob(jobName, xml);
} catch (IOException e) {
// TODO: something other than just rethrow?
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of com.offbytwo.jenkins.model.Job 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;
}
use of com.offbytwo.jenkins.model.Job 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.Job in project beam by apache.
the class TestService method getUrl.
/**
* Returns the jenkins URL for the last successful build.
*
* @param job Map of runner an job name retrieved from configuration
* @param configuration The input configuration
*
* @return The URL of last successful job.
* @throws URISyntaxException
* @throws IOException
*/
default URL getUrl(Map<String, String> job, Configuration configuration) throws URISyntaxException, IOException {
Map<String, Job> jobs = new JenkinsServer(new URI(configuration.getServer())).getJobs();
JobWithDetails jobWithDetails = jobs.get(job.get(job.keySet().toArray()[0])).details();
return new URL(jobWithDetails.getLastSuccessfulBuild().getUrl() + configuration.getJsonapi());
}
Aggregations