@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;
  }
  private void renameJob(Job from, String to) throws IOException {
    LOGGER.info(format("Renaming job %s to %s", from.getFullName(), to));

    ItemGroup fromParent = from.getParent();
    ItemGroup toParent = lookupStrategy.getParent(build.getProject(), to);
    if (fromParent != toParent) {
      LOGGER.info(
          format("Moving Job %s to folder %s", fromParent.getFullName(), toParent.getFullName()));
      if (toParent instanceof DirectlyModifiableTopLevelItemGroup) {
        DirectlyModifiableTopLevelItemGroup itemGroup =
            (DirectlyModifiableTopLevelItemGroup) toParent;
        move(from, itemGroup);
      } else {
        throw new DslException(
            format(
                Messages.RenameJobMatching_DestinationNotFolder(),
                from.getFullName(),
                toParent.getFullName()));
      }
    }
    from.renameTo(FilenameUtils.getName(to));
  }
 public String getName(Job<?, ?> item) {
   return item.getFullName();
 }
예제 #4
0
 public RangeSet getRangeSet(Job job) {
   return getRangeSet(job.getFullName());
 }
예제 #5
0
 /** Returns true if {@link BuildPtr} points to the given job. */
 public boolean is(Job job) {
   return job.getFullName().equals(name);
 }