提交 ee38d15b 编写于 作者: C Christoph Kutzinski

Interrupting SCM checkout should mark the build as aborted instead of failed [JENKINS-4605]

上级 a4ba526d
......@@ -68,6 +68,7 @@ import org.xml.sax.SAXException;
import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
......@@ -557,7 +558,6 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
}
private void checkout(BuildListener listener) throws Exception {
try {
for (int retryCount=project.getScmCheckoutRetryCount(); ; retryCount--) {
// for historical reasons, null in the scm field means CVS, so we need to explicitly set this to something
// in case check out fails and leaves a broken changelog.xml behind.
......@@ -578,6 +578,8 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
}
} catch (AbortException e) {
listener.error(e.getMessage());
} catch (InterruptedIOException e) {
throw (InterruptedException)new InterruptedException().initCause(e);
} catch (IOException e) {
// checkout error not yet reported
e.printStackTrace(listener.getLogger());
......@@ -589,11 +591,6 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
listener.getLogger().println("Retrying after 10 seconds");
Thread.sleep(10000);
}
} catch (InterruptedException e) {
listener.getLogger().println(Messages.AbstractProject_ScmAborted());
LOGGER.log(Level.INFO, AbstractBuild.this + " aborted", e);
throw new RunnerAbortedException();
}
}
/**
......
......@@ -416,7 +416,7 @@ public abstract class SCM implements Describable<SCM>, ExtensionPoint {
*
* @throws InterruptedException
* interruption is usually caused by the user aborting the build.
* this exception will cause the build to fail.
* this exception will cause the build to be aborted.
*/
public abstract boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath workspace, BuildListener listener, File changelogFile) throws IOException, InterruptedException;
......
......@@ -23,10 +23,20 @@
*/
package hudson.scm;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Node;
import hudson.model.Result;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
......@@ -56,4 +66,25 @@ public class ScmTest extends HudsonTestCase {
p.delete();
assertTrue(callback[0]);
}
@Bug(4605)
public void testAbortDuringCheckoutMarksBuildAsAborted() throws IOException, InterruptedException, ExecutionException {
FreeStyleProject p = createFreeStyleProject();
p.setScm(new NullSCM() {
@Override
public boolean checkout(AbstractBuild<?, ?> build,
Launcher launcher, FilePath remoteDir,
BuildListener listener, File changeLogFile)
throws IOException, InterruptedException {
throw new InterruptedException();
}
private Object writeReplace() { // don't really care about save
return new NullSCM();
}
});
FreeStyleBuild build = p.scheduleBuild2(0).get();
assertEquals(Result.ABORTED, build.getResult());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册