Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 Sep 22, 2016
1 parent 27d9b73 commit 3c85fd7
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions core/src/main/java/hudson/tasks/CommandInterpreter.java
Expand Up @@ -51,6 +51,11 @@ public abstract class CommandInterpreter extends Builder {
*/
protected final String command;

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

public CommandInterpreter(String command) {
this.command = command;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 3c85fd7

Please sign in to comment.