From 6aa6b171d634064c975e016326e0e08ea2e0664b Mon Sep 17 00:00:00 2001 From: Tom Huybrechts Date: Mon, 8 Mar 2010 21:40:48 +0100 Subject: [PATCH] SetBuildDescription command --- .../cli/SetBuildDescriptionCommand.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java diff --git a/core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java b/core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java new file mode 100644 index 0000000000..8429fe73f1 --- /dev/null +++ b/core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java @@ -0,0 +1,48 @@ +package hudson.cli; + +import hudson.Extension; +import hudson.model.AbstractProject; +import hudson.model.Run; +import hudson.remoting.Callable; + +import java.io.IOException; +import java.io.Serializable; + +import org.apache.commons.io.IOUtils; +import org.kohsuke.args4j.Argument; + +@Extension +public class SetBuildDescriptionCommand extends CLICommand implements Serializable { + + @Override + public String getShortDescription() { + return "Sets the description 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="DESCRIPTION",required=true,usage="Description to be set. '=' to read from stdin.", index=2) + public String description; + + protected int run() throws Exception { + Run run = job.getBuildByNumber(number); + run.checkPermission(Run.UPDATE); + + if ("=".equals(description)) { + description = channel.call(new Callable() { + public String call() throws IOException { + return IOUtils.toString(System.in); + } + }); + } + + run.setDescription(description); + + return 0; + } + +}