From 297aff0c8b1684e3ff8fd06f7dd9d3fb7d426312 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 9 Aug 2011 19:08:58 -0700 Subject: [PATCH] [FIXED JENKINS-9126] added 'set-build-displayname' CLI command. --- changelog.html | 3 ++ .../cli/SetBuildDisplayNameCommand.java | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 core/src/main/java/hudson/cli/SetBuildDisplayNameCommand.java diff --git a/changelog.html b/changelog.html index e6bf8fdb69..6bd59c14b9 100644 --- a/changelog.html +++ b/changelog.html @@ -77,6 +77,9 @@ Upcoming changes (issue 10414)
  • Added a dignosis CLI command to report the current granted authorities. +
  • + Added a CLI command to set display name of the build + (issue 9126)
  • Added an option in CLI build command to check for SCM changes before carrying out a build (issue 9968) diff --git a/core/src/main/java/hudson/cli/SetBuildDisplayNameCommand.java b/core/src/main/java/hudson/cli/SetBuildDisplayNameCommand.java new file mode 100644 index 0000000000..e90273261f --- /dev/null +++ b/core/src/main/java/hudson/cli/SetBuildDisplayNameCommand.java @@ -0,0 +1,47 @@ +package hudson.cli; + +import hudson.Extension; +import hudson.model.AbstractProject; +import hudson.model.Run; +import hudson.remoting.Callable; +import org.apache.commons.io.IOUtils; +import org.kohsuke.args4j.Argument; + +import java.io.IOException; +import java.io.Serializable; + +@Extension +public class SetBuildDisplayNameCommand extends CLICommand implements Serializable { + + @Override + public String getShortDescription() { + return "Sets the displayName of a build"; + } + + @Argument(metaVar="JOB", usage="Name of the job to build", required=true, index=0) + public transient AbstractProject job; + + @Argument(metaVar="BUILD#", usage="Number of the build", required=true, index=1) + public int number; + + @Argument(metaVar="DISPLAYNAME", required=true, usage="DisplayName to be set. '-' to read from stdin.", index=2) + public String displayName; + + protected int run() throws Exception { + Run run = job.getBuildByNumber(number); + run.checkPermission(Run.UPDATE); + + if ("-".equals(displayName)) { + displayName = channel.call(new Callable() { + public String call() throws IOException { + return IOUtils.toString(System.in); + } + }); + } + + run.setDisplayName(displayName); + + return 0; + } + +} -- GitLab