Skip to content

Commit

Permalink
Merge pull request #149 from jglick/robustness-JENKINS-48867
Browse files Browse the repository at this point in the history
[JENKINS-48867] A failure during branch indexing should be propagated so branches are not lost
  • Loading branch information
jglick authored Oct 15, 2020
2 parents 86b869e + fc459fe commit aa44ae5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -195,22 +196,19 @@ 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);
StandardUsernameCredentials credentials = getCredentials(request.credentialsId(), getOwner());
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,
Expand Down Expand Up @@ -266,21 +264,18 @@ 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);
StandardUsernameCredentials credentials = getCredentials(request.credentialsId(), context);
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class MercurialSCMSource2Test {
@ClassRule public static DockerClassRule<MercurialContainer> 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();
Expand Down Expand Up @@ -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"));
}

}

0 comments on commit aa44ae5

Please sign in to comment.