Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[FIXED JENKINS-11877] Use AbortException rather than returning false …
…to indicate checkout failure
- Loading branch information
Showing
with
30 additions
and 33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -395,26 +395,23 @@ public boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath wo | ||
} else { | ||
e.printStackTrace(listener.error("Failed to determine whether workspace can be reused")); | ||
} | ||
throw new AbortException("Failed to determine whether workspace can be reused"); | ||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jglick
Member
|
||
} | ||
|
||
if (canReuseExistingWorkspace) { | ||
update(build, launcher, repository, listener); | ||
} else { | ||
clone(build, launcher, repository, listener); | ||
} | ||
|
||
try { | ||
determineChanges(build, launcher, listener, changelogFile, repository); | ||
} catch (IOException e) { | ||
listener.error("Failed to capture change log"); | ||
e.printStackTrace(listener.getLogger()); | ||
throw new AbortException("Failed to capture change log"); | ||
} | ||
return true; | ||
} | ||
|
||
private boolean canReuseWorkspace(FilePath repo, | ||
@@ -514,7 +511,7 @@ private void determineChanges(AbstractBuild<?, ?> build, Launcher launcher, Buil | ||
/* | ||
* Updates the current repository. | ||
*/ | ||
private void update(AbstractBuild<?, ?> build, Launcher launcher, FilePath repository, BuildListener listener) | ||
throws InterruptedException, IOException { | ||
EnvVars env = build.getEnvironment(listener); | ||
|
||
@@ -528,45 +525,45 @@ private boolean update(AbstractBuild<?, ?> build, Launcher launcher, FilePath re | ||
} else { | ||
e.printStackTrace(listener.error("Failed to pull")); | ||
} | ||
throw new AbortException("Failed to pull"); | ||
} | ||
|
||
int updateExitCode; | ||
try { | ||
updateExitCode = hg.run("update", "--clean", "--rev", getBranch(env)).pwd(repository).join(); | ||
} catch (IOException e) { | ||
listener.error("Failed to update"); | ||
e.printStackTrace(listener.getLogger()); | ||
throw new AbortException("Failed to update"); | ||
} | ||
if (updateExitCode != 0) { | ||
listener.error("Failed to update"); | ||
throw new AbortException("Failed to update"); | ||
} | ||
|
||
if(clean) { | ||
if (hg.cleanAll().pwd(repository).join() != 0) { | ||
listener.error("Failed to clean unversioned files"); | ||
throw new AbortException("Failed to clean unversioned files"); | ||
} | ||
} | ||
|
||
String tip = hg.tip(repository); | ||
if (tip != null) { | ||
build.addAction(new MercurialTagAction(tip)); | ||
} | ||
} | ||
|
||
/** | ||
* Start from scratch and clone the whole repository. | ||
*/ | ||
private void clone(AbstractBuild<?,?> build, Launcher launcher, FilePath repository, BuildListener listener) | ||
throws InterruptedException, IOException { | ||
try { | ||
repository.deleteRecursive(); | ||
} catch (IOException e) { | ||
e.printStackTrace(listener.error("Failed to clean the repository checkout")); | ||
throw new AbortException("Failed to clean the repository checkout"); | ||
} | ||
|
||
EnvVars env = build.getEnvironment(listener); | ||
@@ -593,19 +590,21 @@ private boolean clone(AbstractBuild<?,?> build, Launcher launcher, FilePath repo | ||
args.add(source); | ||
} | ||
args.add(repository.getRemote()); | ||
int cloneExitCode; | ||
try { | ||
cloneExitCode = hg.run(args).join(); | ||
} catch (IOException e) { | ||
if (causedByMissingHg(e)) { | ||
listener.error("Failed to clone " + source + " because hg could not be found;" + | ||
" check that you've properly configured your Mercurial installation"); | ||
} else { | ||
e.printStackTrace(listener.error("Failed to clone "+source)); | ||
} | ||
throw new AbortException("Failed to clone "+source); | ||
} | ||
if(cloneExitCode!=0) { | ||
listener.error("Failed to clone "+source); | ||
throw new AbortException("Failed to clone "+source); | ||
} | ||
|
||
if (cachedSource != null && cachedSource.isUseCaches() && !cachedSource.isUseSharing()) { | ||
@@ -614,7 +613,7 @@ private boolean clone(AbstractBuild<?,?> build, Launcher launcher, FilePath repo | ||
String hgrcText = hgrc.readToString(); | ||
if (!hgrcText.contains(cachedSource.getRepoLocation())) { | ||
listener.error(".hg/hgrc did not contain " + cachedSource.getRepoLocation() + " as expected:\n" + hgrcText); | ||
throw new AbortException(".hg/hgrc did not contain " + cachedSource.getRepoLocation() + " as expected:\n" + hgrcText); | ||
} | ||
hgrc.write(hgrcText.replace(cachedSource.getRepoLocation(), source), null); | ||
} | ||
@@ -632,8 +631,6 @@ private boolean clone(AbstractBuild<?,?> build, Launcher launcher, FilePath repo | ||
if (tip != null) { | ||
build.addAction(new MercurialTagAction(tip)); | ||
} | ||
} | ||
|
||
@Override | ||
@jglick
that logic seems to be broken
If we get that
canReuseExistingWorkspace
false, then we shouldn't throw abortException, because later there should be full checkoutI guess throw should be only in
if (causedByMissingHg(e)) {
branch