diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index e8e80a7ae7..1e1a74f3a4 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -11,6 +11,11 @@ import java.io.IOException; import java.io.PrintStream; import java.util.Calendar; +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; + +import javax.servlet.ServletException; + /** * Base implementation of {@link Run}s that build software. * @@ -103,4 +108,20 @@ public abstract class AbstractBuild
,R extends Abs
protected abstract Result doRun(BuildListener listener) throws Exception;
}
+
+
+ /**
+ * Stops this build if it's still going.
+ *
+ * If we use this/executor/stop URL, it causes 404 if the build is already killed,
+ * as {@link #getExecutor()} returns null.
+ */
+ public synchronized void doStop( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
+ Executor e = getExecutor();
+ if(e!=null)
+ e.doStop(req,rsp);
+ else
+ // nothing is building
+ rsp.forwardToPreviousPage(req);
+ }
}
diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java
index 4871b89982..a9f495068f 100644
--- a/core/src/main/java/hudson/model/Build.java
+++ b/core/src/main/java/hudson/model/Build.java
@@ -15,11 +15,8 @@ import hudson.tasks.Fingerprinter.FingerprintAction;
import hudson.tasks.Publisher;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.triggers.SCMTrigger;
-import org.kohsuke.stapler.StaplerRequest;
-import org.kohsuke.stapler.StaplerResponse;
import org.xml.sax.SAXException;
-import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -321,21 +318,6 @@ public final class Build extends AbstractBuild