提交 91a43c52 编写于 作者: K kohsuke

Added the "build" CLI command that can not only schedule a new build, but also...

Added the "build" CLI command that can not only schedule a new build, but also wait until its completion.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@22663 71c3de6d-444a-0410-be80-ed276b4c234a
上级 2b12abbd
package hudson.cli;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Cause;
import hudson.Extension;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import java.util.concurrent.Future;
import java.io.PrintStream;
/**
* Builds a job, and optionally waits until its completion.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class BuildCommand extends CLICommand {
@Override
public String getShortDescription() {
return "Builds a job, and optionall waits until its completion.";
}
@Argument(metaVar="JOB",usage="Name of the job to build",required=true)
public AbstractProject<?,?> job;
@Option(name="-s",usage="Wait until the completion/abortion of the command")
public boolean sync = false;
protected int run() throws Exception {
Future<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause());
if (!sync) return 0;
AbstractBuild b = f.get(); // wait for the completion
stdout.println("Completed "+b.getFullDisplayName()+" : "+b.getResult());
return b.getResult().ordinal;
}
@Override
protected void printUsageSummary(PrintStream stderr) {
stderr.println(
"Starts a build, and optionally waits for a completion.\n" +
"Aside from general scripting use, this command can be\n" +
"used to invoke another job from within a build of one job.\n" +
"With the -s option, this command changes the exit code based on\n" +
"the outcome of the build (exit code 0 indicates a success.)\n"
);
}
public static class CLICause extends Cause {
public String getShortDescription() {
return "Started by command line";
}
}
}
......@@ -182,9 +182,19 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
protected void printUsage(PrintStream stderr, CmdLineParser p) {
stderr.println("java -jar hudson-cli.jar "+getName()+" args...");
printUsageSummary(stderr);
p.printUsage(stderr);
}
/**
* Called while producing usage. This is a good method to override
* to render the general description of the command that goes beyond
* a single-line summary.
*/
protected void printUsageSummary(PrintStream stderr) {
stderr.println(getShortDescription());
}
/**
* Creates a clone to be used to execute a command.
*/
......
......@@ -65,7 +65,7 @@ public final class Result implements Serializable, CustomExportedBean {
/**
* Bigger numbers are worse.
*/
private final int ordinal;
public final int ordinal;
/**
* Default ball color for this status.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册