/**
   * Tests to trigger builds with two diffetent patch sets. Expecting two build to be scheduled with
   * one cause each.
   *
   * @throws Exception if so.
   */
  @LocalData
  public void testDoubleTriggeredBuildsOfDifferentChange() throws Exception {
    FreeStyleProject project = DuplicatesUtil.createGerritTriggeredJob(this, "projectX");
    server.waitForCommand(GERRIT_STREAM_EVENTS, 2000);
    PluginImpl.getInstance().triggerEvent(Setup.createPatchsetCreated());
    PatchsetCreated patchsetCreated = Setup.createPatchsetCreated();
    patchsetCreated.getChange().setNumber("2000");
    PluginImpl.getInstance().triggerEvent(patchsetCreated);

    RunList<FreeStyleBuild> builds = waitForBuilds(project, 2, 5000);
    assertEquals(2, builds.size());
    assertSame(Result.SUCCESS, builds.get(0).getResult());
    assertSame(Result.SUCCESS, builds.get(1).getResult());

    int count = 0;
    for (Cause cause : builds.get(0).getCauses()) {
      if (cause instanceof GerritCause) {
        count++;
      }
    }
    assertEquals(1, count);
    count = 0;
    for (Cause cause : builds.get(1).getCauses()) {
      if (cause instanceof GerritCause) {
        count++;
        assertNotNull(((GerritCause) cause).getContext());
        assertNotNull(((GerritCause) cause).getEvent());
      }
    }
    assertEquals(1, count);
  }
  /**
   * Tests to trigger a build with the same patch set twice, one is a manual event and the other a
   * normal. Expecting one build to be scheduled with two causes of different type..
   *
   * @throws Exception if so.
   */
  @LocalData
  public void testDoubleTriggeredBuildOfDifferentType() throws Exception {
    FreeStyleProject project = DuplicatesUtil.createGerritTriggeredJob(this, "projectX");
    server.waitForCommand(GERRIT_STREAM_EVENTS, 2000);
    PatchsetCreated patchsetCreated = Setup.createPatchsetCreated();
    ManualPatchsetCreated mpc = new ManualPatchsetCreated();
    mpc.setChange(patchsetCreated.getChange());
    mpc.setPatchset(patchsetCreated.getPatchSet());
    mpc.setUploader(patchsetCreated.getUploader());
    mpc.setUserName("bobby");
    PluginImpl.getInstance().triggerEvent(Setup.createPatchsetCreated());
    PluginImpl.getInstance().triggerEvent(mpc);

    RunList<FreeStyleBuild> builds = waitForBuilds(project, 1, 5000);
    FreeStyleBuild build = builds.get(0);
    assertSame(Result.SUCCESS, build.getResult());
    assertEquals(1, builds.size());

    int count = 0;
    for (Cause cause : build.getCauses()) {
      if (cause instanceof GerritCause) {
        count++;
        assertNotNull(((GerritCause) cause).getContext());
        assertNotNull(((GerritCause) cause).getContext().getThisBuild());
        assertNotNull(((GerritCause) cause).getEvent());
      }
    }
    assertEquals(2, count);
  }
Exemplo n.º 3
0
 /**
  * Gets the list of {@link Build}s that include changes by this user, by the timestamp order.
  *
  * <p>TODO: do we need some index for this?
  */
 @WithBridgeMethods(List.class)
 public RunList getBuilds() {
   List<AbstractBuild> r = new ArrayList<AbstractBuild>();
   for (AbstractProject<?, ?> p : Hudson.getInstance().getAllItems(AbstractProject.class))
     for (AbstractBuild<?, ?> b : p.getBuilds()) if (b.hasParticipant(this)) r.add(b);
   return RunList.fromRuns(r);
 }
Exemplo n.º 4
0
 public void doRssFailed(StaplerRequest req, StaplerResponse rsp)
     throws IOException, ServletException {
   rss(
       req,
       rsp,
       " regression builds",
       RunList.fromRuns(getBuilds()).regressionOnly(),
       Run.FEED_ADAPTER);
 }
 /**
  * Same test logic as {@link #testBuildLatestPatchsetOnly()} except the trigger is configured to
  * not cancel the previous build.
  *
  * @throws Exception if so.
  */
 @LocalData
 public void testNotBuildLatestPatchsetOnly() throws Exception {
   ((Config) PluginImpl.getInstance().getConfig()).setGerritBuildCurrentPatchesOnly(false);
   FreeStyleProject project = DuplicatesUtil.createGerritTriggeredJob(this, "projectX");
   project.getBuildersList().add(new SleepBuilder(2000));
   server.waitForCommand(GERRIT_STREAM_EVENTS, 2000);
   PatchsetCreated firstEvent = Setup.createPatchsetCreated();
   PluginImpl.getInstance().triggerEvent(firstEvent);
   AbstractBuild firstBuild = waitForBuildToStart(firstEvent, 2000);
   PatchsetCreated secondEvent = Setup.createPatchsetCreated();
   secondEvent.getPatchSet().setNumber("2");
   PluginImpl.getInstance().triggerEvent(secondEvent);
   RunList<FreeStyleBuild> builds = waitForBuilds(project, 2, 5000);
   assertEquals(2, builds.size());
   assertSame(Result.SUCCESS, firstBuild.getResult());
   assertSame(Result.SUCCESS, builds.getFirstBuild().getResult());
   assertSame(Result.SUCCESS, builds.getLastBuild().getResult());
 }
  @SuppressWarnings("rawtypes")
  public List<ReportObject> getRedBuildList(String viewName) {
    View view = Jenkins.getInstance().getView(viewName);
    RunList builds = view.getBuilds();
    RunList failedBuilds = builds.failureOnly();
    Set<String> processedProjects = new HashSet<String>();
    List<ReportObject> objects = new LinkedList<ReportObject>();
    @SuppressWarnings("unchecked")
    Iterator<Run> failedBuildIterator = failedBuilds.iterator();
    while (failedBuildIterator.hasNext()) {
      Job parent = failedBuildIterator.next().getParent();
      if (!processedProjects.contains(parent.getFullName())) {
        Run lastBuildCompleted = parent.getLastBuild();
        if (lastBuildCompleted != null && lastBuildCompleted.isBuilding()) {
          lastBuildCompleted = lastBuildCompleted.getPreviousBuild();
        }
        if (parent.getLastFailedBuild() != null
            && lastBuildCompleted != null
            && lastBuildCompleted.getResult().isWorseThan(Result.SUCCESS)
            && (lastBuildCompleted.getAction(VolunteerAction.class) != null)) {
          objects.add(ReportObject.getInstance(parent, lastBuildCompleted));
          processedProjects.add(parent.getFullName());
        }
      } else {
        System.out.println("Already processed parent " + parent.getDisplayName());
      }
    }

    Collections.sort(
        objects,
        new Comparator<ReportObject>() {
          @Override
          public int compare(ReportObject o1, ReportObject o2) {
            return (o2.getFailedBuilds() - o1.getFailedBuilds()) * 10
                + o1.getLastFailedBuildname().compareTo(o2.getLastFailedBuildname());
          }
        });

    return objects;
  }
Exemplo n.º 7
0
 public void doRssLatest(StaplerRequest req, StaplerResponse rsp)
     throws IOException, ServletException {
   final List<Run> lastBuilds = new ArrayList<Run>();
   for (final TopLevelItem item : Hudson.getInstance().getItems()) {
     if (!(item instanceof Job)) continue;
     for (Run r = ((Job) item).getLastBuild(); r != null; r = r.getPreviousBuild()) {
       if (!(r instanceof AbstractBuild)) continue;
       final AbstractBuild b = (AbstractBuild) r;
       if (b.hasParticipant(this)) {
         lastBuilds.add(b);
         break;
       }
     }
   }
   rss(req, rsp, " latest build", RunList.fromRuns(lastBuilds), Run.FEED_ADAPTER_LATEST);
 }
 public TimelineEventList doData(
     StaplerRequest req, @QueryParameter long min, @QueryParameter long max) throws IOException {
   TimelineEventList result = new TimelineEventList();
   for (Run r : builds.byTimestamp(min, max)) {
     Event e = new Event();
     e.start = r.getTime();
     e.end = new Date(r.timestamp + r.getDuration());
     e.title = r.getFullDisplayName();
     // what to put in the description?
     // e.description = "Longish description of event "+r.getFullDisplayName();
     // e.durationEvent = true;
     e.link = req.getContextPath() + '/' + r.getUrl();
     BallColor c = r.getIconColor();
     e.color = String.format("#%06X", c.getBaseColor().darker().getRGB() & 0xFFFFFF);
     e.classname = "event-" + c.noAnime().toString() + " " + (c.isAnimated() ? "animated" : "");
     result.add(e);
   }
   return result;
 }
 @Deprecated
 public Run<?, ?> getLastBuild() {
   return builds.getLastBuild();
 }
Exemplo n.º 10
0
 public BuildTimelineWidget(RunList<?> builds) {
   this.builds = builds.limit(20); // TODO instead render lazily
 }
Exemplo n.º 11
0
 private void rss(
     StaplerRequest req, StaplerResponse rsp, String suffix, RunList runs, FeedAdapter adapter)
     throws IOException, ServletException {
   RSS.forwardToRss(getDisplayName() + suffix, getUrl(), runs.newBuilds(), adapter, req, rsp);
 }
Exemplo n.º 12
0
 public void doRssAll(StaplerRequest req, StaplerResponse rsp)
     throws IOException, ServletException {
   rss(req, rsp, " all builds", RunList.fromRuns(getBuilds()), Run.FEED_ADAPTER);
 }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 14
0
 /**
  * Gets the read-only view of all the builds.
  *
  * @return never null. The first entry is the latest build.
  */
 @Exported
 @WithBridgeMethods(List.class)
 public RunList<RunT> getBuilds() {
   return RunList.fromRuns(_getRuns().values());
 }