com.offbytwo.jenkins.model.Job Java Examples
The following examples show how to use
com.offbytwo.jenkins.model.Job.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassicJobApi.java From blueocean-plugin with MIT License | 6 votes |
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; }
Example #2
Source File: JenkinsServerIntegration.java From verigreen with Apache License 2.0 | 6 votes |
@Test public void testCreateJob() throws Exception { final String sourceJob = "pr"; final String jobName = "test-job-" + UUID.randomUUID().toString(); String sourceXml = server.getJobXml(sourceJob); server.createJob(jobName, sourceXml); Map<String, Job> jobs = server.getJobs(); assertTrue(jobs.containsKey(jobName)); JobWithDetails thisJob = jobs.get(jobName).details(); assertNotNull(thisJob); assertTrue(thisJob.getBuilds().size() == 0); thisJob.build(ImmutableMap.of("foo_param", "MUST_PROVIDE_VALUES_DEFAULTS_DONT_WORK")); // wait to see if the job finishes, but with a timeout Future<Void> future = executor.submit(new PerformPollingTest(server, jobName)); // If this times out, either jenkins is slow or our test failed! // IME, usually takes about 10-15 seconds future.get(30, TimeUnit.SECONDS); Build b = server.getJobs().get(jobName).details().getLastSuccessfulBuild(); assertTrue(b != null); }
Example #3
Source File: BentenJenkinsClient.java From benten with MIT License | 5 votes |
public String build(String jobName){ logger.info("Building Jenkins job with jobName: " + jobName); try { Job job = jenkins.getJob(jobName); logger.info(jobName + " is buildable: " + job.details().isBuildable()); int lastBuildNumber = job.details().getLastBuild().getNumber(); int nextBuildNumber = job.details().getNextBuildNumber(); QueueReference queueReference = job.build(); logger.debug(job.toString()); int waitFor = 0; while(job.details().isInQueue()){ waitFor++; logger.info("Job in queue"); Thread.sleep(5000); if(waitFor>4) return "Job is built successfully, but is in Queue"; } JobWithDetails jobWithDetails =job.details(); if(job.details().getBuildByNumber(nextBuildNumber).details().isBuilding()) { logger.info("Jenkins job "+ jobName +" is building with Build Number: " + nextBuildNumber); return "Jenkins job "+ jobName +" is building with Build Number: " + nextBuildNumber; } else { logger.info("Jenkins job is stuck for :" + jobName); return "Jenkins job is stuck for :" + jobName; } } catch (Exception e) { logger.info("Failed to build Jenkins job with jobName: " + jobName); e.printStackTrace(); throw new BentenJenkinsException(e.getMessage()); } }
Example #4
Source File: ClassicJobApi.java From blueocean-plugin with MIT License | 5 votes |
private void createFolderImpl(Job folder, String folderName) throws IOException { String path = base + "/"; if (folder != null) { path = folder.getUrl().replace("+", "%20"); } path += "createItem"; ImmutableMap<String, Object> params = ImmutableMap.of("mode", "com.cloudbees.hudson.plugins.folder.Folder", "name", folderName, "from", "", "Submit", "OK"); try { Unirest.post(path).basicAuth(admin.username, admin.password).fields(params).asString(); } catch (UnirestException e) { throw new IOException(e); } }
Example #5
Source File: JenkinsVerifier.java From verigreen with Apache License 2.0 | 4 votes |
public static Job getJobToVerify() { Job jobToVerify = null; int jobRetries = getJobRetryCounter(); int retries = 1; while(retries <= jobRetries) { try { VerigreenLogger.get().log( JenkinsVerifier.class.getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Attempting to retrieve job for verification...", retries)); jobToVerify = CollectorApi.getJenkinsServer().getJob(CollectorApi.getVerificationJobName().toLowerCase()); if(jobToVerify != null) { VerigreenLogger.get().log( JenkinsVerifier.class.getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Job for verification was retrieved successfully after [%s] retries", retries)); break; } else { // in case the job does not exist in Jenkins (wrong job name in the config properties) VerigreenLogger.get().log( JenkinsVerifier.class.getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Failed to retrieve job for verification. Retrying...")); retries++; } } catch (IOException e) { // in case the job does exist, but due to network issues (communication with Jenkins), we get an IOException and // the method fails to retrieve the job VerigreenLogger.get().error( JenkinsVerifier.class.getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Failed to retrieve job for verification. Retrying..."),e); retries++; } } if(jobToVerify == null) { VerigreenLogger.get().error( JenkinsVerifier.class.getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Failed get job for verification after [%s] retries", retries - 1)); CollectorApi.getVerigreenNeededLogic().sendEmailNotification("Failed get job for verification", "<span style='font-family:Metric;'>Failed get job for verification: "+CollectorApi.getVerificationJobName()+". Please contact your DevOps engineer, there might be a load on Jenkins that prevents creating new verification jobs.</span>", new String[] { VerigreenNeededLogic.properties.getProperty("email.address") }, VerigreenNeededLogic.getSignature()); } return jobToVerify; }