Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-48867] A failure during branch indexing should be propagated so branches are not lost #149

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}

}