@Restricted(DoNotUse.class) // used from Jelly public String getCausesDescription() { List<Cause> causes = getCauses(); StringBuilder s = new StringBuilder(); for (Cause c : causes) { s.append(c.getShortDescription()).append('\n'); } return s.toString(); }
/** * Return the GerritCause of the specific item if any, otherwise return null. * @param item The item * @return the GerritCause */ private GerritCause getGerritCause(Item item) { for (Cause cause : item.getCauses()) { if (cause.getClass().equals(GerritCause.class)) { // we only block the exact type, not sub classes return (GerritCause)cause; } } return null; }
@Restricted(DoNotUse.class) // used from Jelly public String getCausesDescription() { List<Cause> causes = getCauses(); StringBuilder s = new StringBuilder(); for (Cause c : causes) { s.append(c.getShortDescription()).append('\n'); } return s.toString(); }
GhprbCause qcause = null; for (Cause cause : queueItem.getCauses()) { if (cause instanceof GhprbCause) { qcause = (GhprbCause) cause;
if (checkCausedByGerrit(event, item.getCauses())) { Queue.getInstance().cancel(item);
public static void cancelBuild(Job job, Build build) { String buildUid = build.getMetadata().getUid(); Jenkins jenkins = Jenkins.getInstance(); if (jenkins != null) { Queue buildQueue = jenkins.getQueue(); for (Queue.Item item : buildQueue.getItems()) { for (Cause cause : item.getCauses()) { if (cause instanceof BuildCause && ((BuildCause) cause).getUid().equals(buildUid)) { buildQueue.cancel(item); cancelOpenShiftBuild(build); return; } } } for (Object obj : job.getNewBuilds()) { if (obj instanceof WorkflowRun) { WorkflowRun b = (WorkflowRun) obj; BuildCause cause = b.getCause(BuildCause.class); if (cause != null && cause.getUid().equals(buildUid)) { Executor e = b.getExecutor(); if (e != null) { e.interrupt(ABORTED); break; } } } } cancelOpenShiftBuild(build); } }
public static boolean isQueued(AbstractProject project, AbstractBuild firstBuild) { if (!project.isInQueue()) { return false; } else if (firstBuild == null) { return true; } List<Cause.UpstreamCause> causes = Util.filter(project.getQueueItem().getCauses(), Cause.UpstreamCause.class); @SuppressWarnings("unchecked") List<AbstractProject<?,?>> upstreamProjects = project.getUpstreamProjects(); for (AbstractProject<?, ?> upstreamProject : upstreamProjects) { AbstractBuild upstreamBuild = BuildUtil.match(upstreamProject.getBuilds(), firstBuild); if (upstreamBuild != null) { for (Cause.UpstreamCause upstreamCause : causes) { if (upstreamBuild.getNumber() == upstreamCause.getUpstreamBuild() && upstreamProject.getRelativeNameFrom(JenkinsUtil.getInstance()).equals( upstreamCause.getUpstreamProject())) { return true; } } } } return false; }
@Override public boolean isUnblocked(Queue.Item item) { final List<Cause> causes = item.getCauses(); for (Cause cause : causes) { if (cause instanceof GitHubPRCause) { final GitHubPRCause gitHubPRCause = (GitHubPRCause) cause; final Set<String> causeLabels = gitHubPRCause.getLabels(); if (getLabel() != null) { if (causeLabels.containsAll(label.getLabelsSet())) { if (item.task instanceof Job<?, ?>) { final Job<?, ?> job = (Job<?, ?>) item.task; LOGGER.debug("Unblocking job item {} with matched labels {}", job.getFullName(), label.getLabelsSet()); } return true; } } } } return false; }
/** * Gets all upstream builds that triggered argument queue item. * @param item the queue item to find upstream builds for * @return set of upstream builds */ public static Set<AbstractBuild> getUpstreamBuilds(Queue.Item item) { Set<AbstractBuild> upstreamBuilds = new HashSet<AbstractBuild>(); for (Cause cause : item.getCauses()) { if (cause instanceof Cause.UpstreamCause) { Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause)cause; Run<?, ?> upstreamRun = upstreamCause.getUpstreamRun(); if (upstreamRun != null && upstreamRun instanceof AbstractBuild) { upstreamBuilds.add((AbstractBuild)upstreamRun); } } } return Collections.unmodifiableSet(upstreamBuilds); }
public static List<TriggerCause> getTriggeredBy(Job project, Run<?, ?> build) { Set<TriggerCause> result = new HashSet<>(); List<Cause> causes; if (build == null && project.isInQueue()) { causes = project.getQueueItem().getCauses(); } else { if (build != null) { causes = build.getCauses(); } else { return new ArrayList<>(); } } for (Cause cause : causes) { result.add(CauseResolver.getTrigger(cause)); } return new ArrayList<>(result); }
/** * Gets the queue ids of all upstream projects that triggered argument queue item. * @param item the queue item to find upstream projects for * @return set of upstream project names */ public static Set<Long> getUpstreamQueueIds(Queue.Item item) { Set<Long> upstreamProjects = new HashSet<Long>(); for (Cause cause : item.getCauses()) { if (cause instanceof Cause.UpstreamCause) { Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause)cause; Run<?, ?> run = upstreamCause.getUpstreamRun(); upstreamCause.getUpstreamProject(); if (run != null) { upstreamProjects.add(run.getQueueId()); } } } return Collections.unmodifiableSet(upstreamProjects); }
/** * Return the GerritCause of the specific item if any, otherwise return null. * @param item The item * @return the GerritCause */ private GerritCause getGerritCause(Queue.Item item) { for (Cause cause : item.getCauses()) { if (cause instanceof GerritCause) { return (GerritCause)cause; } } return null; }
private void cancelPreviousJobsInQueueThatMatch(@Nonnull BitbucketCause bitbucketCause) { logger.fine("Looking for queued jobs that match PR ID: " + bitbucketCause.getPullRequestId()); Queue queue = getInstance().getQueue(); for (Queue.Item item : queue.getItems()) { if (hasCauseFromTheSamePullRequest(item.getCauses(), bitbucketCause)) { logger.fine("Canceling item in queue: " + item); queue.cancel(item); } } }
private void cancelPreviousJobsInQueueThatMatch(@Nonnull StashCause stashCause) { logger.fine("Looking for queued jobs that match PR ID: " + stashCause.getPullRequestId()); Queue queue = Jenkins.getInstance().getQueue(); for (Queue.Item item : queue.getItems()) { if (hasCauseFromTheSamePullRequest(item.getCauses(), stashCause)) { logger.info("Canceling item in queue: " + item); queue.cancel(item); } } }
@Override public BuildCause getCause() { for (final Cause cause : this.item.getCauses()) { if (cause instanceof BuildCause) { return (BuildCause) cause; } } return BuildCause.NULL_BUILD_CAUSE; }
private GitLabWebHookCause getGitLabWebHookCauseData(Queue.Item item) { for (Cause cause : item.getCauses()) { if (cause instanceof GitLabWebHookCause) { return (GitLabWebHookCause) cause; } } return null; }