コード例 #1
0
    public String getTasksAsJson() {

      Map<String, List<String>> taskNameLists = new HashMap<String, List<String>>();

      for (NexusDescriptor desc : nexusMap.values()) {
        NexusClient client =
            new NexusJerseyClient(desc.getUrl(), desc.getUser(), desc.getPassword());
        client.init();
        if (client.ping()) {
          List<ScheduledServiceListResource> serviceList =
              client.get("schedules", ScheduledServiceListResourceResponse.class).getData();
          if (serviceList != null && serviceList.size() > 0) {
            List<String> serviceNameList = new ArrayList<String>();
            for (ScheduledServiceListResource servise : serviceList) {
              serviceNameList.add(servise.getName());
            }
            taskNameLists.put(desc.getName(), serviceNameList);
          }
        }
      }

      return JSONObject.fromObject(taskNameLists).toString();
    }
コード例 #2
0
  @Override
  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {

    listener.getLogger().println("Start to submit Nexus scheduled tasks.");

    // Verify configuration of Nexus is still valid.
    if (selectedNexus == null) {
      listener.getLogger().println("Nexus you choise is invalid.");
      listener.getLogger().println("Please check your Jenkins's configuration.");
      return false;
    }

    // Verify Nexus is running.
    NexusClient client =
        new NexusJerseyClient(
            selectedNexus.getUrl(), selectedNexus.getUser(), selectedNexus.getPassword());
    client.init();
    if (!client.ping()) {
      listener
          .getLogger()
          .println(
              "Fail to connect Nexus. URL: "
                  + selectedNexus.getUrl()
                  + ", User: "******"Please check your Nexus is working.");
      return false;
    }

    TaskUtil taskUtil = new TaskUtil(client);

    // List<TaskStatus> statusList = new ArrayList<TaskStatus>();

    // Build ToDo list
    List<ScheduledServiceListResource> todoList = new ArrayList<ScheduledServiceListResource>();

    for (String taskName : tasks.split(",\\s*")) {
      if (!taskName.matches("\\s*")) {
        List<ScheduledServiceListResource> queryResults = taskUtil.fastFetchTasks(taskName);
        if (queryResults != null) {
          todoList.addAll(queryResults);
        } else {
          listener
              .getLogger()
              .println("WARNING: There is no shceduled task whose name is " + taskName + ".");
        }
      }
    }

    // Execute tasks.
    TaskRunner runner = new TaskRunner(client);
    for (ScheduledServiceListResource task : todoList) {
      TaskStatus status = runner.exec(task.getId());
      listener
          .getLogger()
          .println(
              "Submitting... [id: "
                  + task.getId()
                  + ", name: "
                  + task.getName()
                  + ", type: "
                  + task.getTypeName()
                  + "]");
      if (status.equals(TaskStatus.NG) || status.equals(TaskStatus.NG_UNKNOWN)) {
        listener.getLogger().println(task.getId() + ": Return NG status. Please Check your Nexus.");
        return false;
      } else if (status.equals(TaskStatus.WARNING_STILL_RUNNING)) {
        listener
            .getLogger()
            .println("WARNING: This task is still running. Jenkins skipped queueing.");
      }
    }

    listener.getLogger().println("End to submit Nexus scheduled tasks successfully.");
    return true;
  }