public FormValidation doCheckTargets(@AncestorInPath AbstractProject<?,?> project, @QueryParameter String value) throws IOException { if (project == null) { return FormValidation.ok(); } return FilePath.validateFileMask(project.getSomeWorkspace(),value); }
public FormValidation doCheck(@AncestorInPath AbstractProject project, @QueryParameter String value) { // Require CONFIGURE permission on this project if(!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok(); for (String name : Util.tokenize(fixNull(value), ",")) { name = name.trim(); if (Helper.getActiveInstance().getItem(name,project) == null) { final AbstractProject<?,?> nearest = AbstractProject.findNearest(name); return FormValidation.error(Messages.BuildTrigger_NoSuchProject(name, nearest != null ? nearest.getName() : null)); } } return FormValidation.ok(); }
/** * Validate the value for a remote (repository) location. */ @RequirePOST public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath Item context, @QueryParameter String remote, @QueryParameter String value) { // Test the connection only if we may use the credentials (cf. hudson.plugins.git.UserRemoteConfig.DescriptorImpl.doCheckUrl) if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) || context != null && !context.hasPermission(CredentialsProvider.USE_ITEM)) { return FormValidation.ok(); } return checkCredentialsId(req, context, remote, value); }
/** * Form validation method. */ public FormValidation doCheck(@AncestorInPath AccessControlled subject, @AncestorInPath AbstractProject current, @QueryParameter String value ) { // Require CONFIGURE permission on this project if(!subject.hasPermission(Item.CONFIGURE)) return FormValidation.ok(); StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),","); while(tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); Item item = Hudson.getInstance().getItemByFullName(projectName,Item.class); if(item==null) return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName,AbstractProject.findNearest(projectName).getName())); if(!(item instanceof AbstractProject)) return FormValidation.error(Messages.BuildTrigger_NotBuildable(projectName)); if (StringUtils.equals(projectName, current.getName())) { return FormValidation.error(Messages.BuildTrigger_FailedUsingCurrentProject()); } } return FormValidation.ok(); }
public FormValidation doCheckCredentialsId(@AncestorInPath ItemGroup context, @QueryParameter String value) { AccessControlled _context = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (_context == null || !_context.hasPermission(Computer.CONFIGURE)) { return FormValidation.ok(); // no need to alarm a user that cannot configure } for (ListBoxModel.Option o : CredentialsProvider.listCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, Collections.<DomainRequirement>singletonList(SSHLauncher.SSH_SCHEME), SSHAuthenticator.matcher(Connection.class))) { if (StringUtils.equals(value, o.value)) { return FormValidation.ok(); } } return FormValidation.error(Messages.SSHLauncher_SelectedCredentialsMissing()); }
/** * Performs syntax check. */ public FormValidation doCheckScmpoll_spec(@QueryParameter String value, @QueryParameter boolean ignorePostCommitHooks, @AncestorInPath Item item) { if (StringUtils.isBlank(value)) { if (ignorePostCommitHooks) { return FormValidation.ok(Messages.SCMTrigger_no_schedules_no_hooks()); } else { return FormValidation.ok(Messages.SCMTrigger_no_schedules_hooks()); } } else { return Jenkins.getInstance().getDescriptorByType(TimerTrigger.DescriptorImpl.class) .doCheckSpec(value, item); } } }
public FormValidation doCheck(@AncestorInPath AbstractProject project, @QueryParameter String value) { if (project == null) return FormValidation.ok(Messages.BuildTrigger_ok_ancestor_is_null()); if(!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok(); StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),","); boolean hasProjects = false; while(tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); if (StringUtils.isNotBlank(projectName)) { Item item = Jenkins.getInstance().getItem(projectName,project,Item.class); if (item == null) { Job<?, ?> nearest = Items.findNearest(Job.class, projectName, project.getParent()); String alternative = nearest != null ? nearest.getRelativeNameFrom(project) : "?"; return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName, alternative)); if (!item.hasPermission(auth, Item.BUILD)) { return FormValidation.error(Messages.BuildTrigger_you_have_no_permission_to_build_(projectName));
public FormValidation doCheckUpstreamProjects(@AncestorInPath Job project, @QueryParameter String value) { if (!project.hasPermission(Item.CONFIGURE)) { return FormValidation.ok(); } StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),","); boolean hasProjects = false; while(tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); if (StringUtils.isNotBlank(projectName)) { Job item = Jenkins.getInstance().getItem(projectName, project, Job.class); if (item == null) { Job nearest = Items.findNearest(Job.class, projectName, project.getParent()); String alternative = nearest != null ? nearest.getRelativeNameFrom(project) : "?"; return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoSuchProject(projectName, alternative)); } hasProjects = true; } } if (!hasProjects) { return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoProjectSpecified()); } return FormValidation.ok(); }
public FormValidation doCheckWait(@AncestorInPath ItemGroup<?> context, @QueryParameter boolean value, @QueryParameter String job) { if (!value) { return FormValidation.ok(); } Item item = Jenkins.getActiveInstance().getItem(job, context, Item.class); if (item == null) { return FormValidation.ok(); } if (item instanceof Job) { return FormValidation.ok(); } return FormValidation.error(Messages.BuildTriggerStep_no_wait_for_non_jobs()); }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String value) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(value); } return new StandardListBoxModel().includeAs( ACL.SYSTEM, context, DockerServerCredentials.class, Collections.<DomainRequirement>emptyList()); }
public AutoCompletionCandidates doAutoCompleteChildProjects(@QueryParameter String value, @AncestorInPath Item self, @AncestorInPath ItemGroup container) { return AutoCompletionCandidates.ofJobNames(Job.class,value,self,container); }
public FormValidation doCheckDownstreamProjectNames(@AncestorInPath AbstractProject project, @QueryParameter("downstreamProjectNames") final String value) { final StringTokenizer tokens = new StringTokenizer(Util.fixNull(value), ","); //$NON-NLS-1$ boolean some = false; while (tokens.hasMoreTokens()) { final Item item = Jenkins.getInstance().getItemByFullName(projectName); if (item == null) { return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName, AbstractProject.findNearest(projectName, project.getParent()).getRelativeNameFrom(project))); return FormValidation.error(Messages.BuildTrigger_NotBuildable(projectName)); return FormValidation.error(Messages.BuildTrigger_NoProjectSpecified()); return FormValidation.ok();
/** * Form validation method. */ public FormValidation doCheckNodeListString(@AncestorInPath Item project, @QueryParameter String value) { if (!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok(); StringTokenizer tokens = new StringTokenizer(Util.fixNull(value), ","); boolean hasProjects = false; while (tokens.hasMoreTokens()) { String nodeName = tokens.nextToken().trim(); if (StringUtils.isNotBlank(nodeName)) { final Node node = Jenkins.getInstance().getNode(nodeName); if (node == null) { return FormValidation.error(Messages.NodeListBuildParameterFactory_nodeNotFound(nodeName)); } hasProjects = true; } } if (!hasProjects) { return FormValidation.error(Messages.NodeListBuildParameterFactory_nodeNotDefined()); } return FormValidation.ok(); }
/** * Checks the job name. */ public FormValidation doCheckJobName(@AncestorInPath Item project, @QueryParameter String value ) { final Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { return FormValidation.error("Jenkins instance is not ready"); } if (!project.hasPermission(Item.CONFIGURE) && project.hasPermission(Item.EXTENDED_READ)) { return FormValidation.ok(); } project.checkPermission(Item.CONFIGURE); if (StringUtils.isNotBlank(value)) { // JENKINS-25011: also look for jobs in folders. final AbstractProject p = ItemPathResolver.getByPath(value, project, AbstractProject.class); if (p==null) { // suggest full name so that getBuilds() can find item. AbstractProject nearest = AbstractProject.findNearest(value, project.getParent()); return FormValidation.error( nearest != null ? hudson.tasks.Messages.BuildTrigger_NoSuchProject(value, nearest.getFullName()) : hudson.plugins.promoted_builds.Messages.Shared_noSuchProject(value)); } } return FormValidation.ok(); }
public FormValidation doCheckCredentialsId(@CheckForNull @AncestorInPath Item item, @QueryParameter String credentialsId, @QueryParameter String serverUrl) { if (item == null) { if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.ok(); } } else if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) { return FormValidation.ok(); } if (StringUtils.isBlank(credentialsId)) { return FormValidation.warning(Messages.NPMRegistry_DescriptorImpl_emptyCredentialsId()); } List<DomainRequirement> domainRequirement = URIRequirementBuilder.fromUri(serverUrl).build(); if (CredentialsProvider.listCredentials(StandardUsernameCredentials.class, item, getAuthentication(item), domainRequirement, CredentialsMatchers.withId(credentialsId)).isEmpty()) { return FormValidation.error(Messages.NPMRegistry_DescriptorImpl_invalidCredentialsId()); } return FormValidation.ok(); }
@CheckForNull public FormValidation doCheckTagsDir(StaplerRequest req, @AncestorInPath Item context, @QueryParameter String value) { Jenkins instance = Jenkins.getInstance(); if (instance != null) { SubversionSCM.ModuleLocation.DescriptorImpl desc = instance.getDescriptorByType(SubversionSCM.ModuleLocation.DescriptorImpl.class); if (desc != null) { return desc.doCheckRemote(req, context, value); } } return FormValidation.warning("Unable to check tags directory."); }
/** * Validate the value for a remote (repository) location. */ public FormValidation doCheckRemote(/* TODO unused, delete */StaplerRequest req, @AncestorInPath Item context, @QueryParameter String remote) { // repository URL is required String url = Util.fixEmptyAndTrim(remote); if (url == null) { return FormValidation.error(Messages.SubversionSCM_doCheckRemote_required()); } // Is the repository URL parameterized? if (url.indexOf('$') != -1) { return FormValidation.warning("This repository URL is parameterized, syntax validation skipped"); } // repository URL syntax try { SVNURL.parseURIEncoded(url); } catch (SVNException svne) { LOGGER.log(Level.SEVERE, svne.getMessage()); return FormValidation.error(Messages.SubversionSCM_doCheckRemote_invalidUrl()); } return FormValidation.ok(); }
/** * Performs syntax check. */ public FormValidation doCheckSpec(@QueryParameter String value, @AncestorInPath Item item) { try { CronTabList ctl = CronTabList.create(fixNull(value), item != null ? Hash.from(item.getFullName()) : null); Collection<FormValidation> validations = new ArrayList<>(); updateValidationsForSanity(validations, ctl); updateValidationsForNextRun(validations, ctl); return FormValidation.aggregate(validations); } catch (ANTLRException e) { if (value.trim().indexOf('\n')==-1 && value.contains("**")) return FormValidation.error(Messages.TimerTrigger_MissingWhitespace()); return FormValidation.error(e.getMessage()); } }
public FormValidation doCheckBranchesSpec(@AncestorInPath final Job<?, ?> project, @QueryParameter final String value) { if (!project.hasPermission(Item.CONFIGURE) || containsNoBranches(value)) { return FormValidation.ok(); } try { return checkMatchingBranches(value, getProjectBranches(project)); } catch (GitLabProjectBranchesService.BranchLoadingException e) { return FormValidation.warning(project.hasPermission(Jenkins.ADMINISTER) ? e : null, Messages.GitLabPushTrigger_CannotCheckBranches()); } }
/** * Form validation method. */ public FormValidation doCheck(@AncestorInPath Item project, @QueryParameter String value ) { // Require CONFIGURE permission on this project if(!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok(); StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),","); boolean hasProjects = false; while(tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); if (StringUtils.isNotBlank(projectName)) { Item item = HudsonHelper.getItem(projectName, project, Item.class); if(item==null) return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName, HudsonHelper.getRelativeNameFrom(HudsonHelper.findNearest(projectName,project.getParent()), project.getParent()))); if(!(item instanceof AbstractProject)) return FormValidation.error(Messages.BuildTrigger_NotBuildable(projectName)); hasProjects = true; } } if (!hasProjects) { return FormValidation.error(hudson.plugins.downstream_ext.Messages.DownstreamTrigger_NoProjectSpecified()); } return FormValidation.ok(); }