From 6731ab5db73f4fae24befbcd4bb3390812d9aabc Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Mon, 25 Jul 2016 08:50:25 +0200 Subject: [PATCH] Fixed #169 Added crumbFlag to renameJob o Enhanced API to have renameJob with and without crumbFlag and with support for folders. --- ReleaseNotes.md | 16 ++++ .../com/offbytwo/jenkins/JenkinsServer.java | 80 ++++++++++++++++--- 2 files changed, 86 insertions(+), 10 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 1234fa50..38c16957 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -42,6 +42,21 @@ ### API Changes + [Fixed issue 169 Add crumbFlag to renameJob][issue-169] + + Added supplemental `renameJob` method which supports crumbFlag. Furthermore + added `renameJob` which supports folder with and without `crumbFlag`. + So we now have the following methods to rename jobs: + +```java +public class JenkinsServer { + public void renameJob(String oldJobName, String newJobName) throws IOException; + public void renameJob(String oldJobName, String newJobName, Boolean crumbFlag) throws IOException; + public void renameJob(FolderJob folder, String oldJobName, String newJobName) throws IOException; + public void renameJob(FolderJob folder, String oldJobName, String newJobName, Boolean crumbFlag) throws IOException; +} +``` + [Changing getLocalContext(), setLocalContext()][pull-163] The protected method `getLocalContext()` now returns @@ -514,6 +529,7 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport(); [issue-162]: https://github.com/jenkinsci/java-client-api/issues/162 [issue-165]: https://github.com/jenkinsci/java-client-api/issues/165 [issue-167]: https://github.com/jenkinsci/java-client-api/issues/167 +[issue-169]: https://github.com/jenkinsci/java-client-api/issues/169 [issue-172]: https://github.com/jenkinsci/java-client-api/issues/172 [pull-123]: https://github.com/jenkinsci/java-client-api/pull/123 [pull-149]: https://github.com/jenkinsci/java-client-api/pull/149 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 d68f0a11..565c4ab4 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java @@ -651,14 +651,74 @@ public Build getBuild(QueueItem q) throws IOException { } /** - * Rename a job - * - * @param jobName Existing Job name - * @param newJobName New Job Name - * @throws IOException In case of a failure. - */ - public void renameJob(String jobName, String newJobName) throws IOException { - client.post( - "/job/" + EncodingUtils.encode(jobName) + "/doRename?newName=" + EncodingUtils.encodeParam(newJobName)); - } + * Rename a job + * + * @param oldJobName + * existing job name. + * @param newJobName + * The new job name. + * @throws IOException + * In case of a failure. + */ + public void renameJob(String oldJobName, String newJobName) throws IOException { + renameJob(null, oldJobName, newJobName, false); + } + + /** + * Rename a job + * + * @param oldJobName + * existing job name. + * @param newJobName + * The new job name. + * @param crumbFlag + * true to add crumbIssuer false otherwise. + * @throws IOException + * In case of a failure. + */ + public void renameJob(String oldJobName, String newJobName, Boolean crumbFlag) throws IOException { + renameJob(null, oldJobName, newJobName, crumbFlag); + } + + /** + * Rename a job + * + * @param FolderJob + * The folder. + * @param oldJobName + * existing job name. + * @param newJobName + * The new job name. + * @throws IOException + * In case of a failure. + */ + public void renameJob(FolderJob folder, String oldJobName, String newJobName) throws IOException { + renameJob(folder, oldJobName, newJobName, false); + } + + /** + * Rename a job + * + * @param FolderJob + * The folder. + * @param oldJobName + * existing job name. + * @param newJobName + * The new job name. + * @param crumbFlag + * true to add crumbIssuer false otherwise. + * @throws IOException + * In case of a failure. + */ + public void renameJob(FolderJob folder, String oldJobName, String newJobName, Boolean crumbFlag) throws IOException { + + String path = "/"; + if (folder != null) { + path = folder.getUrl(); + } + client.post( path + + "job/" + EncodingUtils.encode(oldJobName) + "/doRename?newName=" + EncodingUtils.encodeParam(newJobName), crumbFlag); + + } + }