示例#1
0
 public HttpResponse doChangeOfflineCause(@QueryParameter String offlineMessage)
     throws IOException, ServletException {
   checkPermission(DISCONNECT);
   offlineMessage = Util.fixEmptyAndTrim(offlineMessage);
   setTemporarilyOffline(
       true,
       OfflineCause.create(
           hudson.slaves.Messages._SlaveComputer_DisconnectedBy(
               Jenkins.getAuthentication().getName(),
               offlineMessage != null ? " : " + offlineMessage : "")));
   return HttpResponses.redirectToDot();
 }
示例#2
0
  /**
   * If the computer was offline (either temporarily or not), this method will return the cause as a
   * string (without user info).
   *
   * @return empty string if the system was put offline without given a cause.
   */
  @Exported
  public String getOfflineCauseReason() {
    if (offlineCause == null) {
      return "";
    }
    // fetch the localized string for "Disconnected By"
    String gsub_base = hudson.slaves.Messages.SlaveComputer_DisconnectedBy("", "");
    // regex to remove commented reason base string
    String gsub1 = "^" + gsub_base + "[\\w\\W]* \\: ";
    // regex to remove non-commented reason base string
    String gsub2 = "^" + gsub_base + "[\\w\\W]*";

    String newString = offlineCause.toString().replaceAll(gsub1, "");
    return newString.replaceAll(gsub2, "");
  }