From 973958ebc33090b0e33dccc8c87b4bbc760646bd Mon Sep 17 00:00:00 2001 From: Jesper Terkelsen Date: Fri, 25 Aug 2017 23:56:13 +0200 Subject: [PATCH] JENKINS-46472 Ability to modify offline cause for offline computers. Added ability to modify offline cause for offline computers. ComputerWithDetails computer = ... if (!computer.getOffline()){ computer.toggleOffline(); computer.changeOfflineCause("Scheduled for termination"); } --- ReleaseNotes.md | 12 ++++++++++++ .../jenkins/model/ComputerWithDetails.java | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 2c43e996..d73d6f40 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -2,6 +2,18 @@ ## Release 0.3.8 (NOT RELEASED YET) + * [JENKINS-46472](https://issues.jenkins-ci.org/browse/JENKINS-46472) + + Added ability to modify offline cause for offline computers. + + ```java + ComputerWithDetails computer = ... + if (!computer.getOffline()){ + computer.toggleOffline(); + computer.changeOfflineCause("Scheduled for termination"); + } + ``` + * [Fixed Issue 268][issue-268] NullPointerException is thrown unless isRunning() is called first. diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java index b1df2eef..c565f8a2 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java @@ -97,6 +97,23 @@ public void toggleOffline() throws IOException { toggleOffline( false ); } + public void changeOfflineCause(String cause, boolean crumbFlag) throws IOException { + String name; + if ("master".equals(displayName)) { + name = "(master)"; + } else { + name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); + } + + Map data = new HashMap(); + data.put( "offlineMessage", cause ); + client.post_form("/computer/" + name + "/changeOfflineCause?", data, crumbFlag); + } + + public void changeOfflineCause(String cause) throws IOException { + changeOfflineCause(cause, false); + } + public Boolean getManualLaunchAllowed() { return manualLaunchAllowed; }