From f7ac406f6e8362ea90bfd867dada158a2d3a908f Mon Sep 17 00:00:00 2001 From: Chidambaram GS Date: Mon, 26 Mar 2018 09:31:45 +0530 Subject: [PATCH 1/3] Support for Stop and Restarting Jenkins --- .../com/offbytwo/jenkins/JenkinsServer.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java index 4b8cce3b..0cc5eb0f 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java @@ -917,4 +917,74 @@ private String toViewBaseUrl(FolderJob folder, String name) { return toBaseUrl(folder) + "view/" + EncodingUtils.encode(name); } + /** + * Restart Jenkins without waiting for any existing build to complete + * + * @param crumbFlag + * true to add crumbIssuer false + * otherwise. + * @throws IOException + * in case of an error. + */ + public void restart(Boolean crumbFlag) throws IOException { + try { + client.post("/restart", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("restart()", e); + } + } + + /** + * safeRestart: Puts Jenkins into the quiet mode, wait for existing builds + * to be completed, and then restart Jenkins + * + * @param crumbFlag + * true to add crumbIssuer false + * otherwise. + * @throws IOException + * in case of an error. + */ + public void safeRestart(Boolean crumbFlag) throws IOException { + try { + client.post("/safeRestart", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("safeRestart()", e); + } + } + + /** + * Shutdown Jenkins without waiting for any existing build to complete + * + * @param crumbFlag + * true to add crumbIssuer false + * otherwise. + * @throws IOException + * in case of an error. + */ + // + public void exit(Boolean crumbFlag) throws IOException { + try { + client.post("/exit", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("exit()", e); + } + } + + /** + * safeExit: Puts Jenkins into the quiet mode, wait for existing builds to + * be completed, and then shut down Jenkins + * + * @param crumbFlag + * true to add crumbIssuer false + * otherwise. + * @throws IOException + * in case of an error. + */ + public void safeExit(Boolean crumbFlag) throws IOException { + try { + client.post("/safeExit", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("safeExit()", e); + } + } } From ed96644c639d6182f6747243c5d6f131ca091d74 Mon Sep 17 00:00:00 2001 From: Chidambaram GS Date: Tue, 27 Mar 2018 13:45:57 +0530 Subject: [PATCH 2/3] Updated Release notes --- ReleaseNotes.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 39db74ac..8ec3fdba 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -16,8 +16,12 @@ ### API Changes - * ? - + * [Fixed Issue 243][issue-243] + + Added new methods to JenkinsServer for stopping and restarting Jenkins. The methods are restart(Boolean crumbFlag), safeRestart(Boolean crumbFlag), exit(Boolean crumbFlag) and safeExit(Boolean crumbFlag) + + Thanks for that to [Chids](https://github.com/Chids-gs). + ## Release 0.3.7 * Changed Eclipse Formatting configuration. From 58cbcf582d61b962871718bbbb2c8a8d2e034f8f Mon Sep 17 00:00:00 2001 From: Chidambaram GS Date: Tue, 27 Mar 2018 14:04:04 +0530 Subject: [PATCH 3/3] Fixed Link in ReleaseNotes --- ReleaseNotes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 8ec3fdba..89335b2f 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -16,7 +16,7 @@ ### API Changes - * [Fixed Issue 243][issue-243] + * [Fixed Issue 243](https://github.com/jenkinsci/java-client-api/issues/243) Added new methods to JenkinsServer for stopping and restarting Jenkins. The methods are restart(Boolean crumbFlag), safeRestart(Boolean crumbFlag), exit(Boolean crumbFlag) and safeExit(Boolean crumbFlag)