Skip to content

Commit 973958e

Browse files
author
Jesper Terkelsen
committed
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"); }
1 parent 42a15c9 commit 973958e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ReleaseNotes.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
## Release 0.3.8 (NOT RELEASED YET)
44

5+
* [JENKINS-46472](https://issues.jenkins-ci.org/browse/JENKINS-46472)
6+
7+
Added ability to modify offline cause for offline computers.
8+
9+
```java
10+
ComputerWithDetails computer = ...
11+
if (!computer.getOffline()){
12+
computer.toggleOffline();
13+
computer.changeOfflineCause("Scheduled for termination");
14+
}
15+
```
16+
517
* [Fixed Issue 268][issue-268]
618

719
NullPointerException is thrown unless isRunning() is called first.

jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ public void toggleOffline() throws IOException {
9797
toggleOffline( false );
9898
}
9999

100+
public void changeOfflineCause(String cause, boolean crumbFlag) throws IOException {
101+
String name;
102+
if ("master".equals(displayName)) {
103+
name = "(master)";
104+
} else {
105+
name = UrlEscapers.urlPathSegmentEscaper().escape(displayName);
106+
}
107+
108+
Map<String, String> data = new HashMap<String, String>();
109+
data.put( "offlineMessage", cause );
110+
client.post_form("/computer/" + name + "/changeOfflineCause?", data, crumbFlag);
111+
}
112+
113+
public void changeOfflineCause(String cause) throws IOException {
114+
changeOfflineCause(cause, false);
115+
}
116+
100117
public Boolean getManualLaunchAllowed() {
101118
return manualLaunchAllowed;
102119
}

0 commit comments

Comments
 (0)