Java Code Examples for jenkins.model.Jenkins#getAllItems()
The following examples show how to use
jenkins.model.Jenkins#getAllItems() .
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: GogsUtils.java From gogs-webhook-plugin with MIT License | 6 votes |
/** * Search in Jenkins for a item with type T based on the job name * @param jobName job to find, for jobs inside a folder use : {@literal <folder>/<folder>/<jobName>} * @return the Job matching the given name, or {@code null} when not found */ static <T extends Item> T find(String jobName, Class<T> type) { Jenkins jenkins = Jenkins.getActiveInstance(); // direct search, can be used to find folder based items <folder>/<folder>/<jobName> T item = jenkins.getItemByFullName(jobName, type); if (item == null) { // not found in a direct search, search in all items since the item might be in a folder but given without folder structure // (to keep it backwards compatible) for (T allItem : jenkins.getAllItems(type)) { if (allItem.getName().equals(jobName)) { item = allItem; break; } } } return item; }
Example 2
Source File: MissionControlView.java From mission-control-view-plugin with MIT License | 6 votes |
@Exported(name="builds") public Collection<Build> getBuildHistory() { ArrayList<Build> l = new ArrayList<Build>(); Jenkins instance = Jenkins.getInstance(); if (instance == null) return l; List<Job> jobs = instance.getAllItems(Job.class); RunList builds = new RunList(jobs).limit(getBuildsLimit); Pattern r = filterBuildHistory != null ? Pattern.compile(filterBuildHistory) : null; for (Object b : builds) { Run build = (Run)b; Job job = build.getParent(); String buildUrl = build.getAbsoluteUrl(); // Skip Maven modules. They are part of parent Maven project if (job.getClass().getName().equals("hudson.maven.MavenModule")) continue; // If filtering is enabled, skip jobs not matching the filter if (r != null && !r.matcher(job.getFullName()).find()) continue; Result result = build.getResult(); l.add(new Build(job.getName(), build.getFullDisplayName(), build.getNumber(), build.getStartTimeInMillis(), build.getDuration(), result == null ? "BUILDING" : result.toString(), buildUrl)); } return l; }
Example 3
Source File: Cron.java From parameterized-scheduler with MIT License | 6 votes |
private void checkTriggers(Calendar calendar) { Jenkins instance = Jenkins.getInstance(); for (AbstractProject<?, ?> project : instance.getAllItems(AbstractProject.class)) { for (Trigger<?> trigger : project.getTriggers().values()) { if (trigger instanceof ParameterizedTimerTrigger) { LOGGER.fine("cron checking " + project.getName()); ParameterizedTimerTrigger ptTrigger = (ParameterizedTimerTrigger) trigger; try { ptTrigger.checkCronTabsAndRun(calendar); } catch (Throwable e) { // t.run() is a plugin, and some of them throw RuntimeException and other things. // don't let that cancel the polling activity. report and move on. LOGGER.log(Level.WARNING, trigger.getClass().getName() + ".run() failed for " + project.getName(), e); } } } } }
Example 4
Source File: FolderAuthorizationStrategyManagementLink.java From folder-auth-plugin with MIT License | 5 votes |
/** * Get all {@link AbstractFolder}s in the system * * @return full names of all {@link AbstractFolder}s in the system */ @GET @Nonnull @Restricted(NoExternalUse.class) public JSONArray doGetAllFolders() { Jenkins jenkins = Jenkins.get(); jenkins.checkPermission(Jenkins.ADMINISTER); List<AbstractFolder> folders; try (ACLContext ignored = ACL.as(ACL.SYSTEM)) { folders = jenkins.getAllItems(AbstractFolder.class); } return JSONArray.fromObject(folders.stream().map(AbstractItem::getFullName).collect(Collectors.toList())); }
Example 5
Source File: CodeBuilder.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 5 votes |
public ListBoxModel doFillCredentialsIdItems() { final ListBoxModel selections = new ListBoxModel(); SystemCredentialsProvider s = SystemCredentialsProvider.getInstance(); Set<String> displayCredentials = new HashSet<>(); for (Credentials c: s.getCredentials()) { if (c instanceof CodeBuildBaseCredentials) { displayCredentials.add(((CodeBuildBaseCredentials) c).getId()); } } Jenkins instance = Jenkins.getInstance(); if(instance != null) { List<Folder> folders = instance.getAllItems(Folder.class); for(Folder folder: folders) { List<Credentials> creds = CredentialsProvider.lookupCredentials(Credentials.class, (Item) folder); for(Credentials cred: creds) { if (cred instanceof CodeBuildBaseCredentials) { displayCredentials.add(((CodeBuildBaseCredentials) cred).getId()); } } } } for(String credString: displayCredentials) { selections.add(credString); } return selections; }
Example 6
Source File: CodeBuildStep.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 5 votes |
public ListBoxModel doFillCredentialsIdItems() { final ListBoxModel selections = new ListBoxModel(); SystemCredentialsProvider s = SystemCredentialsProvider.getInstance(); Set<String> displayCredentials = new HashSet<>(); for (Credentials c: s.getCredentials()) { if (c instanceof CodeBuildBaseCredentials) { displayCredentials.add(((CodeBuildBaseCredentials) c).getId()); } } Jenkins instance = Jenkins.getInstance(); if(instance != null) { List<Folder> folders = instance.getAllItems(Folder.class); for(Folder folder: folders) { List<Credentials> creds = CredentialsProvider.lookupCredentials(Credentials.class, (Item) folder); for(Credentials cred: creds) { if (cred instanceof CodeBuildBaseCredentials) { displayCredentials.add(((CodeBuildBaseCredentials) cred).getId()); } } } } for(String credString: displayCredentials) { selections.add(credString); } return selections; }
Example 7
Source File: MissionControlView.java From mission-control-view-plugin with MIT License | 4 votes |
@Exported(name="allJobsStatuses") public Collection<JobStatus> getAllJobsStatuses() { String status; ArrayList<JobStatus> statuses = new ArrayList<JobStatus>(); Jenkins instance = Jenkins.getInstance(); if (instance == null) return statuses; Pattern r = filterJobStatuses != null ? Pattern.compile(filterJobStatuses) : null; List<Job> jobs = instance.getAllItems(Job.class); for (Job j : jobs) { // Skip matrix configuration sub-jobs and Maven modules if (j.getClass().getName().equals("hudson.matrix.MatrixConfiguration") || j.getClass().getName().equals("hudson.maven.MavenModule")) continue; // Decode pipeline branch names String fullName = j.getFullName(); String jobUrl = j.getAbsoluteUrl(); try { fullName = URLDecoder.decode(j.getFullName(), "UTF-8"); } catch (java.io.UnsupportedEncodingException e) { e.printStackTrace(); } // If filtering is enabled, skip jobs not matching the filter if (r != null && !r.matcher(fullName).find()) continue; if (j.isBuilding()) { status = "BUILDING"; } else if (!j.isBuildable()) { status = "DISABLED"; } else { Run lb = j.getLastBuild(); if (lb == null) { status = "NOT_BUILT"; } else { Result res = lb.getResult(); status = res == null ? "UNKNOWN" : res.toString(); } } statuses.add(new JobStatus(fullName, status, jobUrl)); } if (filterByFailures) { Collections.sort(statuses, new StatusComparator()); } return statuses; }