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

Added feature allowing to skip cleanup when build fails #3

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 9 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.399</version>
<version>1.424</version>
</parent>

<artifactId>ws-cleanup</artifactId>
<packaging>hpi</packaging>
<name>Jenkins Workspace Cleanup Plugin</name>
<version>0.9-SNAPSHOT</version>
<version>0.9.1-SNAPSHOT</version>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Workspace+Cleanup+Plugin</url>

<developers>
<developer>
<id>vjuranek</id>
<name>Vojtech Juranek</name>
</developer>
<developer>
<id>fwiegerinck</id>
<name>Frank Wiegerinck</name>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/jenkinsci/ws-cleanup-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/ws-cleanup-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/ws-cleanup-plugin</url>
<connection>scm:git:git://github.com/fwiegerinck/ws-cleanup-plugin.git</connection>
<developerConnection>scm:git:[email protected]:fwiegerinck/ws-cleanup-plugin.git</developerConnection>
<url>https://github.com/fwiegerinck/ws-cleanup-plugin</url>
</scm>

<repositories>
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/hudson/plugins/ws_cleanup/WsCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
Expand All @@ -28,12 +29,14 @@ public class WsCleanup extends Notifier {

private final List<Pattern> patterns;
private final boolean deleteDirs;
private final boolean skipWhenFailed;

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

public List<Pattern> getPatterns(){
Expand All @@ -44,13 +47,23 @@ public boolean getDeleteDirs(){
return deleteDirs;
}

@Override


public boolean getSkipWhenFailed() {
return skipWhenFailed;
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().append("\nDeleting project workspace... ");
FilePath workspace = build.getWorkspace();
try {
if (workspace == null || !workspace.exists())
return true;
if ( build.getResult().isWorseOrEqualTo(Result.FAILURE)) {
listener.getLogger().append("skipped for failed build");
return true;
}
if (patterns == null || patterns.isEmpty()) {
workspace.deleteRecursive();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
<f:entry title="${%Apply pattern also on directories}">
<f:checkbox field="deleteDirs" checked="${it.deleteDirs}" />
</f:entry>
<f:entry title="${%Skip when build failed}">
<f:checkbox field="skipWhenFailed" checked="${it.skipWhenFailed}" />
</f:entry>
</f:advanced>
</j:jelly>