@Override public boolean isEmpty() { return !iterator().hasNext(); }
public void doRssFailed(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { rss(req, rsp, " failed builds", getBuilds().failureOnly()); }
/** * Creates a a {@link RunList} combining all the runs of the supplied jobs. * * @param jobs the supplied jobs. * @param <J> the base class of job. * @param <R> the base class of run. * @return the run list. * @since 2.37 */ public static <J extends Job<J,R>, R extends Run<J,R>> RunList<R> fromJobs(Iterable<? extends J> jobs) { List<Iterable<R>> runLists = new ArrayList<>(); for (Job j : jobs) runLists.add(j.getBuilds()); return new RunList<>(combine(runLists)); }
public void doRssLatest(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { final List<Run> lastBuilds = new ArrayList<Run>(); for (AbstractProject<?,?> p : Jenkins.getInstance().allItems(AbstractProject.class)) { for (AbstractBuild<?,?> b = p.getLastBuild(); b != null; b = b.getPreviousBuild()) { if (relatedTo(b)) { lastBuilds.add(b); break; } } } // historically these have been reported sorted by project name, we switched to the lazy iteration // so we only have to sort the sublist of runs rather than the full list of irrelevant projects Collections.sort(lastBuilds, new Comparator<Run>() { @Override public int compare(Run o1, Run o2) { return Items.BY_FULL_NAME.compare(o1.getParent(), o2.getParent()); } }); rss(req, rsp, " latest build", RunList.fromRuns(lastBuilds), Run.FEED_ADAPTER_LATEST); }
private void rss(StaplerRequest req, StaplerResponse rsp, String suffix, RunList runs) throws IOException, ServletException { RSS.forwardToRss(getDisplayName() + suffix, getUrl(), runs.newBuilds(), Run.FEED_ADAPTER, req, rsp); }
/** * Obtains a list of builds, in the descending order, that are within the specified time range [start,end). * * @return can be empty but never null. * @deprecated * as of 1.372. Should just do {@code getBuilds().byTimestamp(s,e)} to avoid code bloat in {@link Job}. */ @WithBridgeMethods(List.class) @Deprecated public RunList<RunT> getBuildsByTimestamp(long start, long end) { return getBuilds().byTimestamp(start,end); }
/** * Tests that event is properly removed if only two different projects are triggered * and one of them is cancelled while in the queue. * * @throws Exception if something goes wrong */ @Test public void testCancelledOneQueueItemOfTwo() throws Exception { FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleProject project2 = jenkinsRule.createFreeStyleProject(); PatchsetCreated event = Setup.createPatchsetCreated(); final GerritCause gerritCause = new GerritCause(event, false); ToGerritRunListener runListener = ToGerritRunListener.getInstance(); runListener.onTriggered(project, event); runListener.onTriggered(project2, event); project.scheduleBuild2(QUIET_PERIOD, gerritCause); QueueTaskFuture<FreeStyleBuild> future2 = project2.scheduleBuild2(QUIET_PERIOD, gerritCause); Item item = waitForBlockedItem(project, TIMEOUT_SECONDS); Queue queue = jenkinsRule.getInstance().getQueue(); queue.doCancelItem(item.getId()); FreeStyleBuild build = future2.get(); assertThat(queue.isEmpty(), equalTo(true)); assertThat(project.getBuilds().size(), equalTo(0)); assertThat(project2.getBuilds().size(), equalTo(1)); assertThat(runListener.isBuilding(event), equalTo(false)); }
/** * Tests that the builds from the MatrixProject can be loaded. */ @Test @LocalData public void testMatrixBuild() { Item item = j.jenkins.getItem("matrixJob"); assertThat("Item is not a MatrixProject", item, instanceOf(MatrixProject.class)); MatrixProject proj = (MatrixProject)item; RunList<MatrixBuild> builds = proj.getBuilds(); assertNotNull(builds); assertTrue("The build list should not be empty", !builds.isEmpty()); MatrixBuild matrixBuild = proj.getFirstBuild(); assertNotNull(matrixBuild.getAction(RetriggerAction.class)); GerritManualCause cause = matrixBuild.getCause(GerritManualCause.class); assertNotNull(cause); BadgeAction action = matrixBuild.getAction(BadgeAction.class); assertNotNull(action); }
public List<TestResult> getList(int start, int end) { List<TestResult> list = new ArrayList<TestResult>(); end = Math.min(end, testObject.getRun().getParent().getBuilds().size()); for (Run<?,?> b: testObject.getRun().getParent().getBuilds().subList(start, end)) { if (b.isBuilding()) continue; TestResult o = testObject.getResultInRun(b); if (o != null) { list.add(o); } } return list; }
public boolean ifSummarizerParserUsed(String filename) { return this.getJob().getBuilds().getLastBuild() .getAction(PerformanceBuildAction.class).getPerformanceReportMap() .getPerformanceReport(filename).ifSummarizerParserUsed(filename); }
/** * Trigger test. * @throws Exception if there is one. */ @Test public void testTriggerWorkflow() throws Exception { jenkinsRule.jenkins.setCrumbIssuer(null); MockGerritServer gerritServer = MockGerritServer.get(jenkinsRule); gerritServer.start(); try { PatchsetCreated event = Setup.createPatchsetCreated(gerritServer.getName()); WorkflowJob job = createWorkflowJob(event); PluginImpl.getHandler_().post(event); // Now wait for the Gerrit server to trigger the workflow build in Jenkins... TestUtils.waitForBuilds(job, 1); WorkflowRun run = job.getBuilds().iterator().next(); jenkinsRule.assertLogContains("Gerrit trigger: patchset-created", run); // Workflow build was triggered successfully. Now lets check make sure the // gerrit plugin sent a verified notification back to the Gerrit Server... JSONObject verifiedMessage = gerritServer.waitForNextVerified(); // System.out.println(gerritServer.lastContent); String message = verifiedMessage.getString("message"); Assert.assertTrue(message.startsWith("Build Successful")); Assert.assertTrue(message.contains("job/WFJob/1/")); JSONObject labels = verifiedMessage.getJSONObject("labels"); assertEquals(1, labels.getInt("Verified")); } finally { gerritServer.stop(); } }
@SuppressWarnings("deprecation") // RunList.size @Test public void useBuildDiscarder() throws Exception { sampleRepo.init(); sampleRepo.write("Jenkinsfile", "properties([buildDiscarder(logRotator(numToKeepStr: '1'))])"); sampleRepo.git("add", "Jenkinsfile"); sampleRepo.git("commit", "--all", "--message=flow"); WorkflowMultiBranchProject mp = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p"); mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false))); WorkflowJob p = scheduleAndFindBranchProject(mp, "master"); assertEquals(1, mp.getItems().size()); r.waitUntilNoActivity(); // #1 built automatically assertEquals(1, p.getBuilds().size()); r.assertBuildStatusSuccess(p.scheduleBuild2(0)); // #2 assertEquals(1, p.getBuilds().size()); r.assertBuildStatusSuccess(p.scheduleBuild2(0)); // #3 assertEquals(1, p.getBuilds().size()); WorkflowRun b3 = p.getLastBuild(); assertEquals(3, b3.getNumber()); assertNull(b3.getPreviousBuild()); }
/** @deprecated see {@link #size()} for why this violates lazy-loading */ @Deprecated public R getFirstBuild() { size(); return first; }
public void doRssLatest(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { final List<Run> lastBuilds = new ArrayList<>(); for (AbstractProject<?, ?> p : Jenkins.get().allItems(AbstractProject.class)) { for (AbstractBuild<?, ?> b = p.getLastBuild(); b != null; b = b.getPreviousBuild()) { if (relatedTo(b)) { lastBuilds.add(b); break; } } } // historically these have been reported sorted by project name, we switched to the lazy iteration // so we only have to sort the sublist of runs rather than the full list of irrelevant projects lastBuilds.sort((o1, o2) -> Items.BY_FULL_NAME.compare(o1.getParent(), o2.getParent())); rss(req, rsp, " latest build", RunList.fromRuns(lastBuilds), Run.FEED_ADAPTER_LATEST); }
public List<TestResult> getList(int start, int end) { List<TestResult> list = new ArrayList<TestResult>(); end = Math.min(end, testObject.getOwner().getParent().getBuilds().size()); for (AbstractBuild<?,?> b: testObject.getOwner().getParent().getBuilds().subList(start, end)) { if (b.isBuilding()) continue; TestResult o = testObject.getResultInBuild(b); if (o != null) { list.add(o); } } return list; }
public void doRssFailed(StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { rss(req, rsp, " failed builds", getBuilds().failureOnly()); } private void rss(StaplerRequest req, StaplerResponse rsp, String suffix, RunList runs) throws IOException, ServletException {