Skip to content
Permalink
Browse files

JENKINS-23896 Give CommandInterpreter.join(Proc p) access to Build

The CommandInterpreter.join(Proc p) method is supposed to be an extension
point to allow an UNSTABLE build result to be set, but it has no access to
the Build object with which to do so.

Add a getBuild() method that returns the build passed to perform(...). A better
API would be a new join(...) with more arguments, but that'd break out of tree
plugins that might already be using this for other purposes.
  • Loading branch information
ringerc authored and stochmim committed Jul 21, 2014
1 parent 27d9b73 commit 3c85fd74cbaf38e39e8675b15dfe6ef6ada91081
Showing with 26 additions and 3 deletions.
  1. +26 −3 core/src/main/java/hudson/tasks/CommandInterpreter.java
@@ -51,6 +51,11 @@
*/
protected final String command;

/**
* The build being run. Valid only during perform(...).
*/
protected AbstractBuild<?,?> build;

public CommandInterpreter(String command) {
this.command = command;
}
@@ -59,12 +64,26 @@ public final String getCommand() {
return command;
}

/**
* Access the current build object.
*
* Useful for {@link #join(Proc p)} for setting build results.
*
* @return The build being run, or null if outside perform(...)
* @since 1.573
*/
protected final AbstractBuild<?,?> getBuild()
{
return build;
}

@Override
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException {
return perform(build,launcher,(TaskListener)listener);
}

public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
this.build = build;
FilePath ws = build.getWorkspace();
if (ws == null) {
Node node = build.getBuiltOn();
@@ -97,6 +116,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_CommandFailed()));
}
this.build = null;
return r==0;
} finally {
try {
@@ -125,9 +145,12 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener
/**
* Reports the exit code from the process.
*
* This allows subtypes to treat the exit code differently (for example by treating non-zero exit code
* as if it's zero, or to set the status to {@link Result#UNSTABLE}). Any non-zero exit code will cause
* the build step to fail.
* This allows subtypes to treat the exit code differently (for example by
* treating non-zero exit code as if it's zero). Any non-zero exit code
* will cause the build step to fail.
*
* To set the status to {@link Result#UNSTABLE}, use {@link #getBuild()} and
* call {@code getBuild().setResult(BuildResult.UNSTABLE); }.
*
* @since 1.549
*/

0 comments on commit 3c85fd7

Please sign in to comment.
You can’t perform that action at this time.