Skip to content

Commit

Permalink
Interrupting SCM checkout should mark the build as aborted instead of…
Browse files Browse the repository at this point in the history
… failed [JENKINS-4605]
  • Loading branch information
kutzi committed Nov 8, 2011
1 parent a4ba526 commit ee38d15
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
9 changes: 3 additions & 6 deletions core/src/main/java/hudson/model/AbstractBuild.java
Expand Up @@ -68,6 +68,7 @@
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;
Expand Down Expand Up @@ -557,7 +558,6 @@ private void preCheckout(Launcher launcher, BuildListener listener) throws IOExc
}

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.
Expand All @@ -578,6 +578,8 @@ private void checkout(BuildListener listener) throws Exception {
}
} 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());
Expand All @@ -589,11 +591,6 @@ private void checkout(BuildListener listener) throws Exception {
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();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/scm/SCM.java
Expand Up @@ -416,7 +416,7 @@ private boolean is1_346OrLater() {
*
* @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;

Expand Down
31 changes: 31 additions & 0 deletions test/src/test/java/hudson/scm/ScmTest.java
Expand Up @@ -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;

Expand Down Expand Up @@ -56,4 +66,25 @@ private Object writeReplace() { // don't really care about save
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());
}
}

0 comments on commit ee38d15

Please sign in to comment.