Permalink
Browse files

[FIXED JENKINS-15236] Add option not to fail the build if some error …

…happens during the cleanup
  • Loading branch information...
vjuranek committed Jan 23, 2013
1 parent 6c2a11f commit 8b56d17030fca6dd6785381f9f11f9afc201f384
@@ -33,14 +33,16 @@
private final List<Pattern> patterns;
private final boolean deleteDirs;
private final boolean skipWhenFailed;
private final boolean notFailBuild;
private final boolean cleanupMatrixParent;

@DataBoundConstructor
// FIXME can't get repeteable to work with a List<String>
public WsCleanup(List<Pattern> patterns, boolean deleteDirs, final boolean skipWhenFailed, final boolean cleanupMatrixParent) {
public WsCleanup(List<Pattern> patterns, boolean deleteDirs, final boolean skipWhenFailed, final boolean notFailBuild, final boolean cleanupMatrixParent) {
this.patterns = patterns;
this.deleteDirs = deleteDirs;
this.skipWhenFailed = skipWhenFailed;
this.notFailBuild = notFailBuild;
this.cleanupMatrixParent = cleanupMatrixParent;
}

@@ -56,13 +58,17 @@ public boolean getSkipWhenFailed() {
return skipWhenFailed;
}

public boolean getNotFailBuild() {
return notFailBuild;
}

public boolean getCleanupMatrixParent() {
return cleanupMatrixParent;
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().append("\nDeleting project workspace... ");
listener.getLogger().append("\nDeleting project workspace... \n");
FilePath workspace = build.getWorkspace();
try {
if (workspace == null || !workspace.exists())
@@ -77,16 +83,21 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
workspace.act(new Cleanup(patterns,deleteDirs));
}
listener.getLogger().append("done\n\n");
} catch (InterruptedException ex) {
} catch (Exception ex) {
Logger.getLogger(WsCleanup.class.getName()).log(Level.SEVERE, null, ex);
if(notFailBuild) {
listener.getLogger().append("Cannot delete workspace: " + ex.getCause() + "\n");
listener.getLogger().append("Option not to fail the build is turned on, so let's continue\n");
return true;
}
return false;
}
return true;
}

public MatrixAggregator createAggregator(MatrixBuild build, Launcher launcher, BuildListener listener) {
if(cleanupMatrixParent)
return new WsCleanupMatrixAggregator(build, launcher, listener, patterns, deleteDirs, skipWhenFailed);
return new WsCleanupMatrixAggregator(build, launcher, listener, patterns, deleteDirs, skipWhenFailed, notFailBuild);
return null;
}

@@ -17,21 +17,23 @@
private final List<Pattern> patterns;
private final boolean deleteDirs;
private final boolean skipWhenFailed;
private final boolean notFailBuild;

public WsCleanupMatrixAggregator(MatrixBuild build, Launcher launcher, BuildListener listener, List<Pattern> patterns,
boolean deleteDirs, boolean skipWhenFailed) {
boolean deleteDirs, boolean skipWhenFailed, boolean notFailBuid) {
super(build, launcher, listener);
this.patterns = patterns;
this.deleteDirs = deleteDirs;
this.skipWhenFailed = skipWhenFailed;
this.notFailBuild = notFailBuid;
}

public boolean endBuild() throws InterruptedException, IOException {
return doWorkspaceCleanup();
}

private boolean doWorkspaceCleanup() throws IOException, InterruptedException {
listener.getLogger().append("\nDeleting matrix project workspace... ");
listener.getLogger().append("\nDeleting matrix project workspace... \n");

//TODO do we want to keep keep child workpsaces if run on the same machine? Make it optional?
/*
@@ -74,8 +76,13 @@ private boolean doWorkspaceCleanup() throws IOException, InterruptedException {
workspace.act(new Cleanup(patterns,deleteDirs));
}
listener.getLogger().append("done\n\n");
} catch (InterruptedException ex) {
} catch (Exception ex) {
Logger.getLogger(WsCleanupMatrixAggregator.class.getName()).log(Level.SEVERE, null, ex);
if(notFailBuild) {
listener.getLogger().append("Cannot delete workspace: " + ex.getCause() + "\n");
listener.getLogger().append("Option not to fail the build is turned on, so let's continue\n");
return true;
}
return false;
}
return true;
@@ -29,6 +29,9 @@
<f:entry title="${%Skip when build failed}">
<f:checkbox field="skipWhenFailed" checked="${it.skipWhenFailed}" />
</f:entry>
<f:entry title="${%Don't fail the build if cleanup fails}" help="/plugin/ws-cleanup/help/notFailBuild.html">
<f:checkbox field="notFailBuild" checked="${it.notFailBuild}" />
</f:entry>
<!--TODO show only for matrix jobs j:when test="" -->
<f:entry title="${%Cleanup workspace of matrix parent}" help="/plugin/ws-cleanup/help/cleanupMatrixParent.html">
<f:checkbox field="cleanupMatrixParent" checked="${it.cleanupMatrixParent}" />
@@ -0,0 +1,4 @@
<p>
During the workspace cleanup various issues can happen, e.g. file cannot be deleted because it's still open and locked by some other process.
By default, when such problem happens, build is marked as failed. If this option is checked, workspace cleanup never marks build as failed.
</p>

0 comments on commit 8b56d17

Please sign in to comment.