From 1f2c71bacd0f1f739464eed6067b899a13cfa904 Mon Sep 17 00:00:00 2001 From: Zuhayr Elahi Date: Fri, 8 Dec 2017 22:26:43 -0800 Subject: [PATCH] Fixed Issue#289 Add a Build.stopPost with a crumbFlag version --- ReleaseNotes.md | 4 +++ .../com/offbytwo/jenkins/model/Build.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index f021d96f..01f072fa 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -2,6 +2,10 @@ ## Release 0.3.8 (NOT RELEASED YET) + * [Fixed Issue 289][issue-289] + + Added a build.stop() method which takes in a crumbFlag + * [Fixed Issue 301][issue-301] diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java index 602b4a8f..048c2bce 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java @@ -149,6 +149,33 @@ public String Stop() throws HttpResponseException, IOException { return ""; } + /** Stops the build which is currently in progress. This version takes in + * a crumbFlag. In some cases , an error is thrown which reads + * "No valid crumb was included in the request". This stop method is used incase + * those issues occur + * + * @param crumbFlag flag used to specify if a crumb is passed into for the request + * @return the client url + * @throws HttpResponseException + * @throws IOException + */ + public String Stop(boolean crumbFlag) throws HttpResponseException, IOException { + try { + + return client.get(url + "stop"); + } catch (IOException ex) { + if (((HttpResponseException) ex).getStatusCode() == 405) { + stopPost(crumbFlag); + return ""; + } + } + return ""; + } + + private void stopPost(boolean crumbFlag) throws HttpResponseException, IOException { + client.post(url + "stop", crumbFlag); + } + private void stopPost() throws HttpResponseException, IOException { client.post(url + "stop"); }