Skip to content

Commit

Permalink
[FIXED JENKINS-15806] - Fail build on failed pull
Browse files Browse the repository at this point in the history
This is an update to pull request #31 and #40
  • Loading branch information
ben-- committed Feb 26, 2014
1 parent c064eba commit 0854a77
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/hudson/plugins/mercurial/MercurialSCM.java
Expand Up @@ -380,7 +380,7 @@ static Set<String> parseStatus(String status) {
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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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;" +
Expand All @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/hudson/plugins/mercurial/SCMTestBase.java
Expand Up @@ -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();
Expand Down

0 comments on commit 0854a77

Please sign in to comment.