Skip to content

Commit

Permalink
Good thing I tried it after merging #5, because it did not work as wr…
Browse files Browse the repository at this point in the history
…itten.

A CLI option can be TopLevelItem, not a subclass (apparently).
Also some other fixups:
Need not be serializable.
Printing to System.out is useless; you need to use CLICommand.stdout.
A meta var for --dump-build-number is meaningless since it takes no arguments.
Making --result be successful by default.
Fixing documentation of --display.
  • Loading branch information
jglick committed Aug 29, 2013
1 parent 00443b2 commit 6df948c
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/main/java/hudson/cli/SetExternalBuildResultCommand.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
package hudson.cli;

import jenkins.model.Jenkins;
import hudson.Extension;
import hudson.model.ExternalJob;
import hudson.model.ExternalRun;
import hudson.model.Run;
import hudson.model.Item;
import hudson.remoting.Callable;
import org.apache.commons.io.IOUtils;
import hudson.model.TopLevelItem;
import org.kohsuke.args4j.Option;

import java.io.IOException;
import java.io.Serializable;
import java.io.InputStream;

/**
* Set build result for external monitor job.
*
* @author David Ostrovsky
*/
@Extension
public class SetExternalBuildResultCommand extends CLICommand implements Serializable {
public class SetExternalBuildResultCommand extends CLICommand {

@Override
public String getShortDescription() {
return "Set external monitor job result.";
}

@Option(name="--job", aliases={"-j"}, metaVar="JOB", usage="Name of the external monitor job", required=true)
public transient ExternalJob job;
public transient TopLevelItem job;

@Option(name="--display", aliases={"-n"}, metaVar="DISPLAY", usage="Display name of the job", required=false)
@Option(name="--display", aliases={"-n"}, metaVar="DISPLAY", usage="Display name of the build", required=false)
public transient String displayName;

@Option(name="--result", aliases={"-r"}, metaVar="RESULT", usage="0: success, 1: fail", required=true)
public transient int result;
@Option(name="--result", aliases={"-r"}, metaVar="RESULT", usage="0: success, 1: fail", required=false)
public transient int result = 0;

@Option(name="--duration", aliases={"-d"}, metaVar="DURATION", usage="Number of milli-seconds it took to run this build", required=false)
public transient long duration = 0;

@Option(name="--log", aliases={"-l"}, metaVar="-|LOG", usage="Log to be set. '-' to read from stdin (gzipped).", required=true)
public String log;

@Option(name="--dump-build-number", aliases={"-b"}, metaVar="BUILD", usage="Log the produced build number to the standard output", required=false)
@Option(name="--dump-build-number", aliases={"-b"}, usage="Log the produced build number to the standard output", required=false)
public boolean dumpBuildNumber;

/**
Expand All @@ -59,7 +53,7 @@ public String getShortDescription() {
* 0: success.
*/
protected int run() throws Exception {
ExternalRun run = job.newBuild();
ExternalRun run = ((ExternalJob) job).newBuild();
run.checkPermission(Run.UPDATE);

if ("-".equals(log)) {
Expand All @@ -73,7 +67,7 @@ protected int run() throws Exception {
}

if (dumpBuildNumber) {
System.out.format("%d\n", run.getNumber());
stdout.println(run.getNumber());
}

return 0;
Expand Down

0 comments on commit 6df948c

Please sign in to comment.