hudson.util.RunList Java Examples
The following examples show how to use
hudson.util.RunList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RunSearch.java From blueocean-plugin with MIT License | 6 votes |
public static Iterable<BlueRun> findRuns(Job job, final Link parent){ final List<BlueRun> runs = new ArrayList<>(); Iterable<Job> pipelines; if(job != null){ pipelines = ImmutableList.of(job); }else{ pipelines = Jenkins.getInstance().getItems(Job.class); } for (Job p : pipelines) { RunList<? extends Run> runList = p.getBuilds(); for (Run r : runList) { BlueRun run = BlueRunFactory.getRun(r, () -> parent); if (run != null) { runs.add(run); } } } return runs; }
Example #2
Source File: FreeStylePipelineTest.java From blueocean-plugin with MIT License | 6 votes |
@Test public void findModernRun() throws Exception { FreeStyleProject freestyle = Mockito.spy(j.createProject(FreeStyleProject.class, "freestyle")); FreeStyleBuild build1 = Mockito.mock(FreeStyleBuild.class); FreeStyleBuild build2 = Mockito.mock(FreeStyleBuild.class); Mockito.when(build1.getParent()).thenReturn(freestyle); Mockito.when(build1.getNextBuild()).thenReturn(build2); Mockito.when(build2.getParent()).thenReturn(freestyle); Mockito.when(build2.getPreviousBuild()).thenReturn(build1); RunList<FreeStyleBuild> runs = RunList.fromRuns(Arrays.asList(build1, build2)); Mockito.doReturn(runs).when(freestyle).getBuilds(); Mockito.doReturn(build2).when(freestyle).getLastBuild(); FreeStylePipeline freeStylePipeline = (FreeStylePipeline) BluePipelineFactory.resolve(freestyle); assertNotNull(freeStylePipeline); BlueRun blueRun = freeStylePipeline.getLatestRun(); assertNotNull(blueRun); Links links = blueRun.getLinks(); assertNotNull(links); assertNotNull(links.get("self")); }
Example #3
Source File: GitHubPRRepository.java From github-integration-plugin with MIT License | 6 votes |
/** * Searches for all builds performed in the runs of current job. * * @return map with keys - numbers of built PRs and values - lists of related builds. */ @Nonnull public Map<Integer, List<Run<?, ?>>> getAllPrBuilds() { Map<Integer, List<Run<?, ?>>> map = new HashMap<>(); final RunList<?> runs = job.getBuilds(); LOG.debug("Got builds for job {}", job.getFullName()); for (Run<?, ?> run : runs) { GitHubPRCause cause = ghPRCauseFromRun(run); if (cause != null) { int number = cause.getNumber(); List<Run<?, ?>> buildsByNumber = map.get(number); if (isNull(buildsByNumber)) { buildsByNumber = new ArrayList<>(); map.put(number, buildsByNumber); } buildsByNumber.add(run); } } return map; }
Example #4
Source File: GitHubBranchRepository.java From github-integration-plugin with MIT License | 6 votes |
/** * Searches for all builds performed in the runs of current job. * * @return map with key - string branch names; value - lists of related builds. */ public Map<String, List<Run<?, ?>>> getAllBranchBuilds() { Map<String, List<Run<?, ?>>> map = new HashMap<>(); final RunList<?> runs = job.getBuilds(); LOG.debug("Got builds for job {}", job.getFullName()); for (Run<?, ?> run : runs) { GitHubBranchCause cause = ghBranchCauseFromRun(run); if (cause != null) { String branchName = cause.getBranchName(); List<Run<?, ?>> buildsByBranchName = map.get(branchName); if (isNull(buildsByBranchName)) { buildsByBranchName = new ArrayList<>(); map.put(branchName, buildsByBranchName); } buildsByBranchName.add(run); } } return map; }
Example #5
Source File: MissionControlView.java From mission-control-view-plugin with MIT License | 6 votes |
@Exported(name="builds") public Collection<Build> getBuildHistory() { ArrayList<Build> l = new ArrayList<Build>(); Jenkins instance = Jenkins.getInstance(); if (instance == null) return l; List<Job> jobs = instance.getAllItems(Job.class); RunList builds = new RunList(jobs).limit(getBuildsLimit); Pattern r = filterBuildHistory != null ? Pattern.compile(filterBuildHistory) : null; for (Object b : builds) { Run build = (Run)b; Job job = build.getParent(); String buildUrl = build.getAbsoluteUrl(); // Skip Maven modules. They are part of parent Maven project if (job.getClass().getName().equals("hudson.maven.MavenModule")) continue; // If filtering is enabled, skip jobs not matching the filter if (r != null && !r.matcher(job.getFullName()).find()) continue; Result result = build.getResult(); l.add(new Build(job.getName(), build.getFullDisplayName(), build.getNumber(), build.getStartTimeInMillis(), build.getDuration(), result == null ? "BUILDING" : result.toString(), buildUrl)); } return l; }
Example #6
Source File: BuildUtilTest.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
private AbstractProject<?,?> createProject(String... shas) { AbstractBuild build = mock(AbstractBuild.class); List<BuildData> buildDatas = new ArrayList<BuildData>(); for(String sha : shas) { BuildData buildData = createBuildData(sha); buildDatas.add(buildData); } when(build.getAction(BuildData.class)).thenReturn(buildDatas.get(0)); when(build.getActions(BuildData.class)).thenReturn(buildDatas); AbstractProject<?, ?> project = mock(AbstractProject.class); when(build.getProject()).thenReturn(project); RunList list = mock(RunList.class); when(list.iterator()).thenReturn(Arrays.asList(build).iterator()); when(project.getBuilds()).thenReturn(list); return project; }
Example #7
Source File: RunContainerImpl.java From blueocean-plugin with MIT License | 5 votes |
@Override public BlueRun get(String name) { RunList<? extends hudson.model.Run> runList = job.getBuilds(); if (name == null) { return BlueRunFactory.getRun(runList.getLastBuild(), pipeline); } for (hudson.model.Run r : runList) { if (r.getId().equals(name)) { return BlueRunFactory.getRun(r, pipeline); } } int number; try { number = Integer.parseInt(name); } catch (NumberFormatException e) { throw new NotFoundException(String.format("Run %s not found in organization %s and pipeline %s", name, pipeline.getOrganizationName(), job.getName())); } for (BlueQueueItem item : QueueUtil.getQueuedItems(pipeline.getOrganization(), job)) { if (item.getExpectedBuildNumber() == number) { return item.toRun(); } } throw new NotFoundException( String.format("Run %s not found in organization %s and pipeline %s", name, pipeline.getOrganizationName(), job.getName())); }
Example #8
Source File: FreeStylePipelineTest.java From blueocean-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-51716") public void findNonNumericRun() throws Exception { FreeStyleProject freestyle = Mockito.spy(j.createProject(FreeStyleProject.class, "freestyle")); FreeStyleBuild build1 = Mockito.mock(FreeStyleBuild.class); FreeStyleBuild build2 = Mockito.mock(FreeStyleBuild.class); Mockito.when(build1.getId()).thenReturn("build1"); Mockito.when(build1.getParent()).thenReturn(freestyle); Mockito.when(build1.getNextBuild()).thenReturn(build2); Mockito.when(build2.getId()).thenReturn("build2"); Mockito.when(build2.getParent()).thenReturn(freestyle); Mockito.when(build2.getPreviousBuild()).thenReturn(build1); RunList<FreeStyleBuild> runs = RunList.fromRuns(Arrays.asList(build1, build2)); Mockito.doReturn(runs).when(freestyle).getBuilds(); Mockito.doReturn(build2).when(freestyle).getLastBuild(); FreeStylePipeline freeStylePipeline = (FreeStylePipeline) BluePipelineFactory.resolve(freestyle); assertNotNull(freeStylePipeline); BlueRun blueRun = freeStylePipeline.getLatestRun(); assertNotNull(blueRun); Links links = blueRun.getLinks(); assertNotNull(links); assertNotNull(links.get("self")); }
Example #9
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 5 votes |
private static int countBuilds(WorkflowJob job, Result status) { RunList<WorkflowRun> builds = job.getNewBuilds(); Iterator<WorkflowRun> iterator = builds.iterator(); int numBuilds = 0; while (iterator.hasNext()) { WorkflowRun build = iterator.next(); Result buildRes = build.getResult(); if (status == null || buildRes == status) { numBuilds++; } } return numBuilds; }
Example #10
Source File: PhabricatorBuildWrapper.java From phabricator-jenkins-plugin with MIT License | 5 votes |
/** * Abort running builds when new build referencing same revision is scheduled to run */ @Override public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { String abortOnRevisionId = getAbortOnRevisionId(build); // If ABORT_ON_REVISION_ID is available if (!CommonUtils.isBlank(abortOnRevisionId)) { // Create a cause of interruption PhabricatorCauseOfInterruption causeOfInterruption = new PhabricatorCauseOfInterruption(build.getUrl()); Run upstreamRun = getUpstreamRun(build); // Get the running builds that were scheduled before the current one RunList<AbstractBuild> runningBuilds = (RunList<AbstractBuild>) build.getProject().getBuilds(); for (AbstractBuild runningBuild : runningBuilds) { Executor executor = runningBuild.getExecutor(); Run runningBuildUpstreamRun = getUpstreamRun(runningBuild); // Ignore builds that were triggered by the same upstream build // Find builds triggered with the same ABORT_ON_REVISION_ID_FIELD if (runningBuild.isBuilding() && runningBuild.number < build.number && abortOnRevisionId.equals(getAbortOnRevisionId(runningBuild)) && (upstreamRun == null || runningBuildUpstreamRun == null || !upstreamRun.equals(runningBuildUpstreamRun)) && executor != null) { // Abort the builds executor.interrupt(Result.ABORTED, causeOfInterruption); } } } }
Example #11
Source File: MyBuildsView.java From DotCi with MIT License | 4 votes |
@Override public RunList getBuilds() { return null; }
Example #12
Source File: DynamicBuildRepository.java From DotCi with MIT License | 4 votes |
public <T extends DbBackedBuild> RunList<T> getBuilds(final DbBackedProject project) { return new DbBackedRunList(project); }
Example #13
Source File: DbBackedProject.java From DotCi with MIT License | 4 votes |
@Override @Exported(name = "allBuilds", visibility = -2) @WithBridgeMethods(List.class) public RunList<B> getBuilds() { return this.dynamicBuildRepository.<B>getBuilds(this); }
Example #14
Source File: JobStateRecipe.java From jenkins-build-monitor-plugin with MIT License | 4 votes |
public JobStateRecipe() { job = mock(Job.class); runList = mock(RunList.class); when(job.isBuildable()).thenReturn(Boolean.TRUE); }