public boolean executeCheck(Item item) { boolean notfound = true; if (Jenkins.getInstance().pluginManager.getPlugin("build-timeout") != null) { if (item.getClass().getName().endsWith("hudson.maven.MavenModuleSet")) { try { Method method = item.getClass().getMethod("getBuildWrappersList"); DescribableList<BuildWrapper,Descriptor<BuildWrapper>> buildWrapperList = ((DescribableList<BuildWrapper,Descriptor<BuildWrapper>>) method.invoke(item)); notfound = !isTimeout(buildWrapperList); } catch (Exception e) { LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause()); notfound = false; } } if (item instanceof Project) { notfound = !isTimeout(((Project) item).getBuildWrappersList()); } if (item instanceof MatrixProject) { notfound = !isTimeout(((MatrixProject) item).getBuildWrappersList()); } } return notfound; }
public boolean executeCheck(Item item) { boolean found = false; if (Jenkins.getInstance().pluginManager.getPlugin("gradle") != null) { if (Jenkins.getInstance().pluginManager.getPlugin("maven-plugin")!=null) { if (item instanceof MavenModuleSet) { found = isGradlew(((MavenModuleSet) item).getPrebuilders()); } } if (item instanceof Project) { found = isGradlew(((Project) item).getBuilders()); } if (item instanceof MatrixProject) { found = isGradlew(((MatrixProject) item).getBuilders()); } } return found; }
public boolean executeCheck(Item item) { LOG.log(Level.FINE, "executeCheck " + item); if (item instanceof Project) { Project project = (Project) item; DescribableList<Publisher, Descriptor<Publisher>> publishersList = project.getPublishersList(); for (Publisher publisher : publishersList) { if (publisher instanceof ArtifactArchiver) { LOG.log(Level.FINEST, "ArtifactChecker " + publisher); return (((ArtifactArchiver) publisher).getArtifacts() == null || (((ArtifactArchiver) publisher).getArtifacts() != null && ((ArtifactArchiver) publisher).getArtifacts().length() == 0)); } } } return false; }
public boolean executeCheck(Item item) { LOG.log(Level.FINE, "executeCheck " + item); boolean found = false; if (Jenkins.getInstance().pluginManager.getPlugin("maven-plugin")!=null) { if (item instanceof MavenModuleSet) { found = isBuilderHarcoded(((MavenModuleSet) item).getPrebuilders()); } } if (item instanceof Project) { found = isBuilderHarcoded (((Project)item).getBuilders()); } if (item instanceof MatrixProject) { found = isBuilderHarcoded (((MatrixProject)item).getBuilders()); } return found; }
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { try { boolean isPProjectBuilding = false; while (true) { isPProjectBuilding = false; List<DTJob> listOfProjects = getAllParentProjects(); for (Project<?, ?> project : listOfProjects) { isPProjectBuilding = checkIfParentIsBuilding(project); } if (!isPProjectBuilding) { return true; } Thread.sleep(1000); } } catch (InterruptedException ex) { return false; } }
@Nonnull @Override public Collection<String> getDockerImagesUsedByJob(@Nonnull Job<?,?> job) { if (job instanceof Project) { Project<? extends Project, ? extends Build> project = (Project<?,? extends Build>)job; Set<String> images = new HashSet<String>(); // check DockerHub build step for matching image ID for (Builder b : project.getBuilders()) { if (b instanceof DockerPullImageBuilder) { images.add(((DockerPullImageBuilder)b).getImage()); } } return images; } else { return Collections.emptySet(); } }
public SlackTextMessage scheduleJob(String projectName) { ACL.impersonate(ACL.SYSTEM); String response = ""; Project project = Jenkins.getInstance().getItemByFullName(projectName, Project.class); boolean success = false; if (project != null) success = project.scheduleBuild(new SlackWebhookCause(this.slackUser)); else return new SlackTextMessage("Could not find project ("+projectName+")\n"); if (success) return new SlackTextMessage("Build scheduled for project "+ projectName+"\n"); else return new SlackTextMessage("Build not scheduled due to an issue with Jenkins"); }
/** * Returns true if this parameter definition is a definition of the given project. * * @since 1.3 * @author dynamic-parameter-plugin * @param parameterUUID UUID of the project parameter * @param project the project to search for this parameter definition. * @return {@code true} if the project contains this parameter definition. */ private static boolean isParameterDefinitionOf(@Nonnull String parameterUUID, @Nonnull Project<?, ?> project) { List<ParameterDefinition> parameterDefinitions = new ArrayList<ParameterDefinition>(); parameterDefinitions.addAll(getProjectParameterDefinitions(project)); for (List<ParameterDefinition> params : getBuildWrapperParameterDefinitions(project).values()) { parameterDefinitions.addAll(params); } for (ParameterDefinition pd : parameterDefinitions) { if (pd instanceof AbstractUnoChoiceParameter) { AbstractUnoChoiceParameter parameterDefinition = (AbstractUnoChoiceParameter) pd; String uuid = parameterDefinition.getRandomName(); if (ObjectUtils.equals(parameterUUID, uuid)) { return true; } } } return false; }
/** * Get parameter definitions associated with {@link BuildWrapper}s of the given {@link Project}. * @param project the project for which the parameter definitions should be found * @return Map */ public static @Nonnull Map<BuildWrapper, List<ParameterDefinition>> getBuildWrapperParameterDefinitions(@Nonnull Project<?, ?> project) { final List<BuildWrapper> buildWrappersList = project.getBuildWrappersList(); final Map<BuildWrapper, List<ParameterDefinition>> result = new LinkedHashMap<BuildWrapper, List<ParameterDefinition>>(); List<ParameterDefinition> value = new ArrayList<ParameterDefinition>(); for (BuildWrapper buildWrapper : buildWrappersList) { final PropertyDescriptor[] propertyDescriptors; try { propertyDescriptors = Introspector.getBeanInfo(buildWrapper.getClass()).getPropertyDescriptors(); } catch (IntrospectionException e) { continue; } for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { addParameterDefinitionsTo(value, buildWrapper, propertyDescriptor); } if (!value.isEmpty()) { result.put(buildWrapper, value); value = new ArrayList<ParameterDefinition>(); } } return result.isEmpty() ? Collections.<BuildWrapper, List<ParameterDefinition>> emptyMap() : result; }
/** * Helper method to determine the template from a given item. * * @param item Item which includes a template. * @return If the item includes a template then the template will be returned. Otherwise <code>null</code>. */ private DockerJobTemplateProperty getJobTemplate(Item item) { if (item.task instanceof Project) { Project<?, ?> project = (Project<?, ?>) item.task; if (project != null) { final DockerJobTemplateProperty p = project.getProperty(DockerJobTemplateProperty.class); if (p != null) return p; // backward compatibility. DockerJobTemplateProperty used to be a nested object in DockerJobProperty DockerJobProperty property = project.getProperty(DockerJobProperty.class); if (property != null) { return property.getDockerJobTemplate(); } } } return null; }
@Override public Action getProjectAction(final AbstractProject<?, ?> project) { log.info("Gebe Projektaktion aus, Klasse: " + project.getClass() + " Instanz von Projekt: " + (project instanceof Project)); if (project instanceof AbstractProject) { lastProject = project; VisualizeAction va = new VisualizeAction(project, this); lastVisulizeAction = va; log.info("Visualizer: " + va.getVisualizer().size()); collectorNames = va.getCollectorNames(); testNames = va.getTestNames(); testcases = new LinkedList<GraphVisualizer>(); for (GraphVisualizer gv : va.getVisualizer()) { log.info("Füge Testcase hinzu: " + gv.getName()); testcases.add(gv); } log.info("Aktion: " + va); return va; } else { log.log(Level.ALL, "Unexpected Class: " + project.getClass()); } return null; }
/** * Get the configured instance for the plugin. * * @param project * @return */ public static NeoLoadPluginOptions getPluginOptions(final AbstractProject<?, ?> project) { final Project<?, ?> proj; NeoBuildAction nba = null; if (!(project instanceof Project)) { return null; } proj = (Project<?, ?>) project; final List<Builder> builders = proj.getBuilders(); for (final Builder b : builders) { if (b instanceof NeoBuildAction) { nba = (NeoBuildAction) b; break; } } return (NeoLoadPluginOptions) nba; }
@Test public void testRegisterJobs_ProjectSingleLabel() throws Exception { Project<?, ?> lemon = createFreeStyleProject("lemon"); lemon.setAssignedLabel(new LabelAtom("linux")); AbstractWorkerThread oneiric = new ExecutorWorkerThread("GearmanServer", 4730, "MyWorker", slave.toComputer(), "master", new NoopAvailabilityMonitor()); oneiric.testInitWorker(); oneiric.registerJobs(); Set<String> functions = oneiric.worker.getRegisteredFunctions(); assertEquals(2, functions.size()); assertTrue(functions.contains("build:lemon")); assertTrue(functions.contains("build:lemon:linux")); }
@Test public void testRegisterJobs_ProjectNoLabel() throws Exception { Project<?, ?> lemon = createFreeStyleProject("lemon"); AbstractWorkerThread oneiric = new ExecutorWorkerThread( "GearmanServer", 4730, "MyWorker", slave.toComputer(), "master", new NoopAvailabilityMonitor()); oneiric.testInitWorker(); oneiric.registerJobs(); Set<String> functions = oneiric.worker.getRegisteredFunctions(); assertEquals(1, functions.size()); assertTrue(functions.contains("build:lemon")); }
@Test public void testRegisterJobs_ProjectNoLabel_Exclusive() throws Exception { Project<?, ?> lemon = createFreeStyleProject("lemon"); DumbSlave exclusive_slave = createOnlineSlave(new LabelAtom("foo")); exclusive_slave.setMode(Mode.EXCLUSIVE); AbstractWorkerThread oneiric = new ExecutorWorkerThread( "GearmanServer", 4730, "MyWorker", exclusive_slave.toComputer(), "master", new NoopAvailabilityMonitor()); oneiric.testInitWorker(); oneiric.registerJobs(); Set<String> functions = oneiric.worker.getRegisteredFunctions(); assertEquals(0, functions.size()); }
@Test public void testRegisterJobs_SlaveOffline() throws Exception { DumbSlave offlineSlave = createSlave(new LabelAtom("oneiric-10")); offlineSlave.setLabelString("ubuntu gcc python-2.4 linux"); Project<?, ?> lemon = createFreeStyleProject("lemon"); lemon.setAssignedLabel(new LabelAtom("linux")); AbstractWorkerThread oneiric = new ExecutorWorkerThread("GearmanServer", 4730, "MyWorker", offlineSlave.toComputer(), "master", new NoopAvailabilityMonitor()); oneiric.testInitWorker(); oneiric.registerJobs(); Set<String> functions = oneiric.worker.getRegisteredFunctions(); assertEquals(0, functions.size()); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Project project) { return new StandardListBoxModel() .withEmptySelection() .withMatching(anyOf( instanceOf(SSHUserPrivateKey.class), instanceOf(UsernamePasswordCredentials.class)), CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, project)); }
/** * Method will return current project. * * @return currentProject. */ public Project getProject() { Project currentProject = null; StaplerRequest request = Stapler.getCurrentRequest(); if (request != null) { currentProject = request.findAncestorObject(Project.class); } return currentProject; }
public boolean executeCheck(Item item) { if (Jenkins.getInstance().pluginManager.getPlugin("ws-cleanup")!=null) { return item instanceof Project && ((Project) item).getPublisher(Descriptor.find("hudson.plugins.ws_cleanup.WsCleanup")) == null; } else { return true; } }
public boolean executeCheck(Item item) { if (item instanceof hudson.model.Project) { return (((Project) item).getDescription() == null || ((Project) item).getDescription().length() == 0); } return false; }
public boolean executeCheck(Item item) { if (item instanceof Project) { DescribableList<Publisher, Descriptor<Publisher>> publishersList = ((Project) item).getPublishersList(); for (Publisher publisher : publishersList) { if (publisher instanceof hudson.tasks.JavadocArchiver) { return ( ((JavadocArchiver) publisher).getJavadocDir() == null || ( ((JavadocArchiver) publisher).getJavadocDir() != null && ((JavadocArchiver) publisher).getJavadocDir().length() == 0 )); } } } return false; }
public boolean executeCheck(Item item) { if (item instanceof Project) { if (Jenkins.getInstance().pluginManager.getPlugin("git")!=null) { if (((Project) item).getScm().getClass().getName().endsWith("GitSCM")) { boolean status = true; try { Method method = ((Project) item).getScm().getClass().getMethod("getExtensions", null); Object extensionsList = method.invoke( ((Project) item).getScm()); if (extensionsList instanceof AbstractList) { for (Object extension : ((AbstractList) extensionsList) ) { if (extension.getClass().getName().endsWith("CloneOption")) { Object isShallow = extension.getClass().getMethod("isShallow", null).invoke(extension); if (isShallow instanceof Boolean) { status = ! ((Boolean) isShallow).booleanValue(); } } } } } catch (Exception e) { LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause()); status = false; } finally { return status; } } } else { LOG.log(Level.FINE, "Plugin GIT doesn't exist"); return false; } } return false; }
/** * Used to delete the auto generated projects used to lock the used * {@link Node}s. * * @param lockProjectName * the locked project name * @throws IOException * @throws InterruptedException * @since 1.0 */ public static void deleteLockingProject(String lockProjectName, PrintStream stream) throws IOException, InterruptedException { for (@SuppressWarnings("rawtypes") Project p : Jenkins.getInstance().getAllItems(FreeStyleProject.class)) { if (lockProjectName.equalsIgnoreCase(p.getName())) { while (p.isBuilding()) { Thread.sleep(1000); } p.delete(); stream.println("Project - " + p.getName() + " has been deleted!"); } } }
public SlackTextMessage getProjectLog(String projectName, String buildNumber) { ACL.impersonate(ACL.SYSTEM); Project project = Jenkins.getInstance().getItemByFullName(projectName, Project.class); if (project == null) return new SlackTextMessage("Could not find project ("+projectName+")\n"); AbstractBuild build = project.getBuildByNumber(Integer.parseInt(buildNumber)); if (build == null) return new SlackTextMessage("Could not find build #"+buildNumber+" for ("+projectName+")\n"); List<String> log = new ArrayList<String>(); try { log = build.getLog(25); } catch (IOException ex) { return new SlackTextMessage("Error occured returning log: "+ex.getMessage()); } String response = "*"+projectName+"* *#"+buildNumber+"*\n"; response += "```"; for (String line : log) { response += line + "\n"; } response += "```"; return new SlackTextMessage(response); }
/** * Get project in Jenkins given its name. * * @since 1.3 * @param projectName project name in Jenkins * @return Project or {@code null} if none with this name * @deprecated The choice is arbitrary if there are multiple matches; use {@link Item#getFullName} and {@link Jenkins#getItemByFullName(String, Class)} instead. */ @SuppressWarnings("rawtypes") public static @CheckForNull Project<?, ?> getProjectByName(@Nonnull String projectName) { Authentication auth = Jenkins.getAuthentication(); for (Project p : Items.allItems(ACL.SYSTEM, Jenkins.getInstance(), Project.class)) { if (p.getName().equals(projectName) && p.getACL().hasPermission(auth, Item.READ)) { return p; } } return null; }
/** * Find the current project give its parameter UUID. * * @author dynamic-parameter-plugin * @since 1.3 * @param parameterUUID parameter UUID * @return {@code null} if the current project cannot be found */ @SuppressWarnings("rawtypes") public static @CheckForNull Project findProjectByParameterUUID(@Nonnull String parameterUUID) { Authentication auth = Jenkins.getAuthentication(); for (Project p : Items.allItems(ACL.SYSTEM, Jenkins.getInstance(), Project.class)) { if (isParameterDefinitionOf(parameterUUID, p) && p.getACL().hasPermission(auth, Item.READ)) { return p; } } return null; }
/** * Get the parameter definitions for the given project. * * @since 1.3 * @author dynamic-parameter-plugin * @param project the project for which the parameter definitions should be found * @return parameter definitions or an empty list */ public static @Nonnull List<ParameterDefinition> getProjectParameterDefinitions(@Nonnull Project<?, ?> project) { ParametersDefinitionProperty parametersDefinitionProperty = project.getProperty(ParametersDefinitionProperty.class); if (parametersDefinitionProperty != null) { List<ParameterDefinition> parameterDefinitions = parametersDefinitionProperty.getParameterDefinitions(); if (parameterDefinitions != null) { return parameterDefinitions; } } return Collections.emptyList(); }
/** * Helper parameters used to render the parameter definition. * @return Map with helper parameters */ private Map<Object, Object> getHelperParameters() { // map with parameters final Map<Object, Object> helperParameters = new LinkedHashMap<Object, Object>(); // First, if the project name is set, we then find the project by its name, and inject into the map Project<?, ?> project = null; if (StringUtils.isNotBlank(this.projectName)) { // first we try to get the item given its name, which is more efficient project = Utils.getProjectByName(this.projectName); } else { // otherwise, in case we don't have the item name, we iterate looking for a job that uses this UUID project = Utils.findProjectByParameterUUID(this.getRandomName()); } if (project != null) { helperParameters.put(JENKINS_PROJECT_VARIABLE_NAME, project); AbstractBuild<?, ?> build = project.getLastBuild(); if (build != null && build.getHasArtifacts()) { helperParameters.put(JENKINS_BUILD_VARIABLE_NAME, build); } } // Here we set the parameter name helperParameters.put(JENKINS_PARAMETER_VARIABLE_NAME, this); // Here we inject the global node properties final Map<String, Object> globalNodeProperties = Utils.getGlobalNodeProperties(); helperParameters.putAll(globalNodeProperties); return helperParameters; }
@Override public Action getProjectAction(Project<?, ?> project) { initPython(); if (pexec.isImplemented(8)) { return (Action) pexec.execPython("get_project_action", project); } else { return super.getProjectAction(project); } }
@SuppressWarnings("rawtypes") public boolean projectIsCompatible(Project p) { if (!(p instanceof InheritanceProject)) { return false; } InheritanceProject ip = (InheritanceProject) p; if (ip.getIsTransient()) { return false; } /* Make sure, that only those projects are shown, whose class is * identical to the caller class. This avoids mix & matching * incompatible classes */ StaplerRequest req = Stapler.getCurrentRequest(); if (req != null) { Job<?,?> currJob = req.findAncestorObject(Job.class); if (currJob != null) { if (currJob.getClass() != ip.getClass()) { //Incompatible classes return false; } } } return true; }
@Override public void onDeleted(Item item) { for (Project<?, ?> p : Hudson.getInstance().getProjects()) { final BuildGraphPipelineSinkTrigger trigger = p.getTrigger(BuildGraphPipelineSinkTrigger.class); if (trigger != null) { if (trigger.onJobDeleted(item.getName())) { try { p.save(); } catch (IOException e) { LOGGER.log(Level.WARNING, String.format("Failed to persist project setting during deletion of %s", item.getName()), e); } } } } }
@Override public void onRenamed(Item item, String oldName, String newName) { for (Project<?, ?> p : Hudson.getInstance().getProjects()) { final BuildGraphPipelineSinkTrigger trigger = p.getTrigger(BuildGraphPipelineSinkTrigger.class); if (trigger != null) { if (trigger.onJobRenamed(oldName, newName)) { try { p.save(); } catch (IOException e) { LOGGER.log(Level.WARNING, String.format("Failed to persist project setting during rename from %s to %s", oldName, newName), e); } } } } }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Project context) { // TODO: also add requirement on host derived from URL ? List<StandardUsernamePasswordCredentials> creds = lookupCredentials(StandardUsernamePasswordCredentials.class, context, ACL.SYSTEM, HTTP_SCHEME, HTTPS_SCHEME); return new StandardUsernameListBoxModel().withAll(creds); }
/** * Get the configured instance for the plugin. * * @param project * @return */ public static NeoBuildAction getNeoBuildAction(final AbstractProject<?, ?> project) { if (!(project instanceof Project)) { return null; } for (final Builder b : ((Project<?, ?>) project).getBuilders()) { if (b instanceof NeoBuildAction) { return (NeoBuildAction) b; } } return null; }
@Test public void testRegisterJobs_ProjectInvalidLabel() throws Exception { Project<?, ?> lemon = createFreeStyleProject("lemon"); lemon.setAssignedLabel(new LabelAtom("bogus")); AbstractWorkerThread oneiric = new ExecutorWorkerThread("GearmanServer", 4730, "MyWorker", slave.toComputer(), "master", new NoopAvailabilityMonitor()); oneiric.testInitWorker(); oneiric.registerJobs(); Set<String> functions = oneiric.worker.getRegisteredFunctions(); assertEquals(0, functions.size()); }
@Test public void testRegisterJobs_ProjectDisabled() throws Exception { Project<?, ?> lemon = createFreeStyleProject("lemon"); lemon.setAssignedLabel(new LabelAtom("linux")); lemon.disable(); AbstractWorkerThread oneiric = new ExecutorWorkerThread("GearmanServer", 4730, "MyWorker", slave.toComputer(), "master", new NoopAvailabilityMonitor()); oneiric.testInitWorker(); oneiric.registerJobs(); Set<String> functions = oneiric.worker.getRegisteredFunctions(); assertEquals(0, functions.size()); }
@Test public void testRegisterJobs_ProjectNotLabel() throws Exception { Project<?, ?> lemon = createFreeStyleProject("lemon"); lemon.setAssignedLabel(new LabelAtom("!linux")); AbstractWorkerThread oneiric = new ExecutorWorkerThread("GearmanServer", 4730, "MyWorker", slave.toComputer(), "master", new NoopAvailabilityMonitor()); oneiric.testInitWorker(); oneiric.registerJobs(); Set<String> functions = oneiric.worker.getRegisteredFunctions(); assertEquals(0, functions.size()); }
public GitLabACL(Job<?, ?> job) { if(job instanceof Project) { this.project = (Project<?, ?>) job; } }