Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-11998] Don't try to clean up without WS.
This checks for ws.exists() before doing any work on it - this prevents an
exception when using org.apache.tools.ant.DirectoryScanner.scan on an
nonexistant directory.
  • Loading branch information
jorgenpt committed Dec 6, 2011
1 parent f630b23 commit 7de3080
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/hudson/plugins/ws_cleanup/PreBuildCleanup.java
Expand Up @@ -50,7 +50,9 @@ public void preCheckout(AbstractBuild build, Launcher launcher,
FilePath ws = build.getWorkspace();
if (ws != null) {
try {
if (patterns == null || patterns.isEmpty()) {
if (!ws.exists()) {
return;
} else if (patterns == null || patterns.isEmpty()) {
ws.deleteContents();
} else {
build.getWorkspace().act(new Cleanup(patterns));
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/hudson/plugins/ws_cleanup/WsCleanup.java
@@ -1,6 +1,7 @@
package hudson.plugins.ws_cleanup;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
Expand Down Expand Up @@ -39,13 +40,17 @@ public List<Pattern> getPatterns(){

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath workspace = build.getWorkspace();
if (workspace == null || !workspace.exists()) {
return true;
}

listener.getLogger().append("\nDeleting project workspace... ");
try {
if (patterns == null || patterns.isEmpty()) {
build.getWorkspace().deleteRecursive();
workspace.deleteRecursive();
} else {
build.getWorkspace().act(new Cleanup(patterns));
workspace.act(new Cleanup(patterns));
}
listener.getLogger().append("done\n\n");
} catch (InterruptedException ex) {
Expand Down

0 comments on commit 7de3080

Please sign in to comment.