From ee38d15b1e7b36336675923135f48194216c3c1d Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Tue, 8 Nov 2011 22:41:39 +0100 Subject: [PATCH] Interrupting SCM checkout should mark the build as aborted instead of failed [JENKINS-4605] --- .../main/java/hudson/model/AbstractBuild.java | 9 ++---- core/src/main/java/hudson/scm/SCM.java | 2 +- test/src/test/java/hudson/scm/ScmTest.java | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index b4cf2ae391..21598da0a8 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -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

,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

,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

,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(); - } } /** diff --git a/core/src/main/java/hudson/scm/SCM.java b/core/src/main/java/hudson/scm/SCM.java index c12521cad0..f6890b6f75 100644 --- a/core/src/main/java/hudson/scm/SCM.java +++ b/core/src/main/java/hudson/scm/SCM.java @@ -416,7 +416,7 @@ public abstract class SCM implements Describable, 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; diff --git a/test/src/test/java/hudson/scm/ScmTest.java b/test/src/test/java/hudson/scm/ScmTest.java index 8c762e7c0f..9d1d91f452 100644 --- a/test/src/test/java/hudson/scm/ScmTest.java +++ b/test/src/test/java/hudson/scm/ScmTest.java @@ -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()); + } } -- GitLab