diff --git a/src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java b/src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java index 21da4022..1dfc8276 100644 --- a/src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java +++ b/src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java @@ -7,6 +7,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import hudson.AbortException; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -195,13 +196,11 @@ public void setCredentialsId(@CheckForNull String credentialsId) { .newRequest(this, listener) ) { MercurialInstallation inst = MercurialSCM.findInstallation(request.installation()); if (inst == null) { - listener.error("No configured Mercurial installation"); - return; + throw new AbortException("No configured Mercurial installation"); } if (!inst.isUseCaches()) { // TODO https://stackoverflow.com/a/11900786/12916 suggests that it may be possible to use a noncaching installation - listener.error("Mercurial installation " + request.installation() + " does not support caches"); - return; + throw new AbortException("Mercurial installation " + request.installation() + " does not support caches"); } final Node node = Jenkins.getInstance(); Launcher launcher = node.createLauncher(listener); @@ -209,8 +208,7 @@ public void setCredentialsId(@CheckForNull String credentialsId) { final FilePath cache = Cache.fromURL(request.source(), credentials, inst.getMasterCacheRoot()) .repositoryCache(inst, node, launcher, listener, true); if (cache == null) { - listener.error("Could not use caches, not fetching branch heads"); - return; + throw new AbortException("Could not use caches, not fetching branch heads"); } try (HgExe hg = new HgExe(inst, credentials, launcher, node, listener, new EnvVars())) { String heads = hg.popen(cache, listener, true, @@ -266,12 +264,10 @@ protected SCMRevision retrieve(@NonNull String thingName, @NonNull TaskListener .newRequest(this, listener)) { MercurialInstallation inst = MercurialSCM.findInstallation(request.installation()); if (inst == null) { - listener.error("No configured Mercurial installation"); - return null; + throw new AbortException("No configured Mercurial installation"); } if (!inst.isUseCaches()) { - listener.error("Mercurial installation " + request.installation() + " does not support caches"); - return null; + throw new AbortException("Mercurial installation " + request.installation() + " does not support caches"); } final Node node = Jenkins.getInstance(); Launcher launcher = node.createLauncher(listener); @@ -279,8 +275,7 @@ protected SCMRevision retrieve(@NonNull String thingName, @NonNull TaskListener final FilePath cache = Cache.fromURL(source, credentials, inst.getMasterCacheRoot()) .repositoryCache(inst, node, launcher, listener, true); if (cache == null) { - listener.error("Could not use caches, not fetching branch heads"); - return null; + throw new AbortException("Could not use caches, not fetching branch heads"); } try (HgExe hg = new HgExe(inst, credentials, launcher, node, listener, new EnvVars())) { String revision = hg.popen(cache, listener, true, diff --git a/src/test/java/hudson/plugins/mercurial/MercurialSCMSource2Test.java b/src/test/java/hudson/plugins/mercurial/MercurialSCMSource2Test.java index 5058f5db..b4bb6ea4 100644 --- a/src/test/java/hudson/plugins/mercurial/MercurialSCMSource2Test.java +++ b/src/test/java/hudson/plugins/mercurial/MercurialSCMSource2Test.java @@ -61,7 +61,7 @@ public class MercurialSCMSource2Test { @ClassRule public static DockerClassRule docker = new DockerClassRule<>(MercurialContainer.class); @Rule public TemporaryFolder tmp = new TemporaryFolder(); - @Issue("JENKINS-42278") + @Issue({"JENKINS-42278", "JENKINS-48867"}) @Test public void withCredentialsId() throws Exception { m.hg("version"); // test environment needs to be able to run Mercurial MercurialContainer container = docker.create(); @@ -97,6 +97,9 @@ public class MercurialSCMSource2Test { WorkflowRun b = p.getLastBuild(); assertNotNull(b); r.assertBuildStatusSuccess(b); + // JENKINS-48867: if indexing fails, should not lose existing branches + sampleRepo.deleteRecursive(); + assertEquals(p, PipelineTest.scheduleAndFindBranchProject(mp, "default")); } }