Skip to content
Permalink
Browse files

[FIXED JENKINS-15806] - Fail build on failed pull

This is an update to pull request #31 and #40
  • Loading branch information...
ben-- committed Feb 26, 2014
1 parent c064eba commit 0854a77f154cbadf71835731ea6f5f90593f42f8
@@ -380,7 +380,7 @@ PollingResult compare(Launcher launcher, TaskListener listener, MercurialTagActi
return result;
}

private void pull(Launcher launcher, FilePath repository, TaskListener listener, Node node, String revision, StandardUsernameCredentials credentials) throws IOException, InterruptedException {
private int pull(Launcher launcher, FilePath repository, TaskListener listener, Node node, String revision, StandardUsernameCredentials credentials) throws IOException, InterruptedException {
HgExe hg = new HgExe(findInstallation(getInstallation()), credentials, launcher, node, listener, /* TODO */new EnvVars());
try {
ArgumentListBuilder cmd = hg.seed(true);
@@ -392,7 +392,7 @@ private void pull(Launcher launcher, FilePath repository, TaskListener listener,
if (cachedSource != null) {
cmd.add(cachedSource.getRepoLocation());
}
HgExe.joinWithPossibleTimeout(
return HgExe.joinWithPossibleTimeout(
hg.launch(cmd).pwd(repository),
true, listener);
} finally {
@@ -593,8 +593,9 @@ private void update(AbstractBuild<?, ?> build, Launcher launcher, FilePath repos
HgExe hg = new HgExe(findInstallation(getInstallation()), credentials, launcher, build.getBuiltOn(), listener, build.getEnvironment(listener));
try {
Node node = Computer.currentComputer().getNode(); // TODO why not build.getBuiltOn()?
int pullExitCode;
try {
pull(launcher, repository, listener, node, toRevision, credentials);
pullExitCode = pull(launcher, repository, listener, node, toRevision, credentials);
} catch (IOException e) {
if (causedByMissingHg(e)) {
listener.error("Failed to pull because hg could not be found;" +
@@ -604,6 +605,10 @@ private void update(AbstractBuild<?, ?> build, Launcher launcher, FilePath repos
}
throw new AbortException("Failed to pull");
}
if (pullExitCode != 0) {
listener.error("Failed to pull");
throw new AbortException("Failed to pull");
}

int updateExitCode;
try {
@@ -718,6 +718,34 @@ public Proc onLaunch(Launcher.ProcStarter p) throws IOException {
}
}

@Bug(15806)
@Test public void testPullReturnCode() throws Exception {
File repoOnline = tmp.newFolder();
File repoOffline = new File(repoOnline.getPath() + "-offline");

m.hg(repoOnline, "init");
m.touchAndCommit(repoOnline, "init");
m.hg(repoOnline, "tag", "init");

FreeStyleProject p = j.createFreeStyleProject();
MercurialSCM a = new MercurialSCM(hgInstallation(), repoOnline.getPath(), null, null, null, null, false);
p.setScm(a);

// First build to get a local checkout (no update on this one)
AbstractBuild<?, ?> b = p.scheduleBuild2(0).get();
assertEquals(Result.SUCCESS, b.getResult());

// Second build fails due to offline repo
repoOnline.renameTo(repoOffline);
b = p.scheduleBuild2(0).get();
assertNotEquals(Result.SUCCESS, b.getResult());

// Third build succeeds after repo returns
repoOffline.renameTo(repoOnline);
b = p.scheduleBuild2(0).get();
assertEquals(Result.SUCCESS, b.getResult());
}

/* TODO the following will pass, but canUpdate is not going to work without further changes:
public void testParameterizedBuildsSource() throws Exception {
p = createFreeStyleProject();

0 comments on commit 0854a77

Please sign in to comment.
You can’t perform that action at this time.