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(); }
private Map<Job,Collection<ReverseBuildTrigger>> calculateCache() { try (ACLContext acl = ACL.as(ACL.SYSTEM)) { final Map<Job, Collection<ReverseBuildTrigger>> result = new WeakHashMap<>(); for (Job<?, ?> downstream : Jenkins.getInstance().allItems(Job.class)) { ReverseBuildTrigger trigger = ParameterizedJobMixIn.getTrigger(downstream, ReverseBuildTrigger.class); if (trigger == null) { continue; } List<Job> upstreams = Items.fromNameList(downstream.getParent(), trigger.getUpstreamProjects(), Job.class); LOGGER.log(Level.FINE, "from {0} see upstreams {1}", new Object[]{downstream, upstreams}); for (Job upstream : upstreams) { if (upstream instanceof AbstractProject && downstream instanceof AbstractProject) { continue; // handled specially } Collection<ReverseBuildTrigger> triggers = result.get(upstream); if (triggers == null) { triggers = new LinkedList<>(); result.put(upstream, triggers); } triggers.remove(trigger); triggers.add(trigger); } } return result; } }
@Override public void onLocationChanged(Item item, final String oldFullName, final String newFullName) { try (ACLContext acl = ACL.as(ACL.SYSTEM)) { for (Job<?, ?> p : Jenkins.getInstance().allItems(Job.class)) { ReverseBuildTrigger t = ParameterizedJobMixIn.getTrigger(p, ReverseBuildTrigger.class); if (t != null) { String revised = Items.computeRelativeNamesAfterRenaming(oldFullName, newFullName, t.getUpstreamProjects(), p.getParent()); if (!revised.equals(t.upstreamProjects)) { t.upstreamProjects = revised; try { p.save(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to persist project setting during rename from " + oldFullName + " to " + newFullName, e); } } } } } } }
if (job.getParent()==build.getParent()) continue; // we are the parent of the build owner, that is almost like we are the owner if(!includeMissing && job.getBuildByNumber(bp.getNumber())==null)
public ItemGroup superGetParent() { return super.getParent(); }
@Override public Collection<LibraryConfiguration> forJob(Job<?,?> job, Map<String,String> libraryVersions) { return forGroup(job.getParent()); }
/** * Checks the provided projects exist in the provided context. * @param projectNames Projects to check. * @param job the configuring job. * @return ok if all projects are found and a warning otherwise. */ public FormValidation doCheckProjectNames(@QueryParameter String projectNames, @CheckForNull @AncestorInPath Job<?, ?> job) { List<String> notFound = checkNotFoundProjects(projectNames, (job != null) ? job.getParent() : null); if (!notFound.isEmpty()) { return FormValidation.warning(Messages.CopyArtifactPermissionProperty_MissingProject(StringUtils.join(notFound, ","))); } return FormValidation.ok(); }
private void onUpdated(Job<?, ?> job) { BranchJobProperty property = job.getProperty(BranchJobProperty.class); if (property != null && job.getParent() instanceof SCMSourceOwner) { // TODO: HACK ALERT! There must/should be a nicer way to do this! updateProperties(job, (SCMSourceOwner) job.getParent(), property.getBranch().getSourceId()); } }
private static ItemGroup getItemGroup(Run<?, ?> build) { return getRootProject(build.getParent()).getParent(); }
private static ItemGroup getItemGroup(Run<?, ?> build) { return getRootProject(build.getParent()).getParent(); }
/** * Fill the project name automatically. * * @param value Seed value. * @param project Ancestor project. * @return the autocompletion candidates. */ public AutoCompletionCandidates doAutoCompleteUpstreamProjectName( @QueryParameter String value, @AncestorInPath Job<?,?> project ) { // Specified Item to allow to autocomplete folders (maybe confusing...). return project == null ? new AutoCompletionCandidates() : AutoCompletionCandidates.ofJobNames(Item.class, value, project, project.getParent()); } }
XmlFile getXmlFile(Job prj) { //default behaviour File rootDir = prj.getRootDir(); File credentialFile = new File(rootDir, credentialsFileName); if (credentialFile.exists()) { return new XmlFile(credentialFile); } //matrix configuration project if (prj instanceof MatrixConfiguration && prj.getParent() != null) { ItemGroup parent = prj.getParent(); return getXmlFile((Job)parent); } if (prj.hasCascadingProject()) { return getXmlFile(prj.getCascadingProject()); } return new XmlFile(new File(rootDir, credentialsFileName)); }
@Override public void onAddedTo(@Nonnull Run run) { if (run.getParent().getParent() instanceof SCMSourceOwner) { // skip multibranch return; } // move polling log from cause to action try { GitHubPRPollingLogAction action = new GitHubPRPollingLogAction(run); FileUtils.writeStringToFile(action.getPollingLogFile(), getPollingLog()); run.replaceAction(action); } catch (IOException e) { LOGGER.warn("Failed to persist the polling log", e); } setPollingLog(null); }
@Override public void onAddedTo(@Nonnull Run run) { if (run.getParent().getParent() instanceof SCMSourceOwner) { // skip multibranch return; } // move polling log from cause to action try { GitHubBranchPollingLogAction action = new GitHubBranchPollingLogAction(run); writeStringToFile(action.getPollingLogFile(), getPollingLog()); run.replaceAction(action); } catch (IOException ex) { LOG.warn("Failed to persist the polling log", ex); } setPollingLog(null); }
/** * Get a {@link BuildActivityCache} from the given {@link Run} * * @param r the {@link Run} to get the {@link BuildActivityCache} from * @return the {@link BuildActivityCache} */ private BuildActivityCache getBuildActivityCacheFromRun(Run r) { BuildActivityCache activity = new BuildActivityCache(r.getTimeInMillis(), r.getParent().getFullName(), r.getNumber()); if (!(r.getParent().getParent() instanceof Hudson)) { activity.setParent(r.getParent().getParent().getFullName()); } activity.setCulprit(BuildUtils.getCulpritFromRunnable(r)); return activity; }
@Override @WithBridgeMethods(value = Jenkins.class, castRequired = true) public ItemGroup getParent() { initPython(); if (pexec.isImplemented(82)) { return (ItemGroup) pexec.execPython("get_parent"); } else { return super.getParent(); } }
@CheckForNull private MavenConfigFolderOverrideProperty getMavenConfigOverrideProperty() { Job<?, ?> job = build.getParent(); // Get the job // Iterate until we find an override or until we reach the top. We need it to be an item to be able to do // getParent, AbstractFolder which has the properties is also an Item for (ItemGroup<?> group = job.getParent(); group != null && group instanceof Item && !(group instanceof Jenkins); group = ((Item) group).getParent()) { if (group instanceof AbstractFolder) { MavenConfigFolderOverrideProperty mavenConfigProperty = ((AbstractFolder<?>) group).getProperties().get(MavenConfigFolderOverrideProperty.class); if (mavenConfigProperty != null && mavenConfigProperty.isOverride()) { return mavenConfigProperty; } } } return null; }
private static GitStatusContext getStatusContext(@Nonnull final Job job) { final String instanceUrl = StringUtils.stripEnd(Jenkins.getInstance().getRootUrl(), "/"); final String projectDisplayName = job.getParent().getFullName() + "/" + job.getDisplayName(); return new GitStatusContext(projectDisplayName, instanceUrl); }
/** * @param copier a project who wants to copy artifacts of this project. * @return whether copier is allowed to copy artifacts of this project. */ public boolean canCopiedBy(Job<?,?> copier) { String copierName = copier.getRelativeNameFrom(owner.getParent()); String absoluteName = String.format("/%s", copier.getFullName()); // Note: getFullName() returns not an absolute path, but a relative path from root... for (String projectName: getProjectNameList()) { if (isNameMatch(copierName, projectName) || isNameMatch(absoluteName, projectName)) { return true; } } return false; }
private void executePullOnDocker(Run<?, ?> build, PrintStream llog, String xImage, DockerClient client) throws DockerException { PullImageResultCallback resultCallback = new PullImageResultCallback() { @Override public void onNext(PullResponseItem item) { if (item.getStatus() != null && item.getProgress() == null) { llog.print(item.getId() + ":" + item.getStatus()); LOG.info("{} : {}", item.getId(), item.getStatus()); } super.onNext(item); } }; PullImageCmd cmd = client.pullImageCmd(xImage); DockerCloud.setRegistryAuthentication(cmd, getRegistry(), build.getParent().getParent()); try { cmd.exec(resultCallback).awaitCompletion(); } catch (InterruptedException e) { throw new DockerClientException("Interrupted while pulling image", e); } }