Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FIXED JENKINS-20056] Delete workspace asynchronously
- Loading branch information
1 parent
0af6bfb
commit 8e31d6a
Showing
6 changed files
with
187 additions
and
23 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
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
67 changes: 67 additions & 0 deletions
67
src/main/java/hudson/plugins/ws_cleanup/RemoteCleaner.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2014 Red Hat, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.ws_cleanup; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.BuildListener; | ||
import hudson.model.AbstractBuild; | ||
import hudson.slaves.EnvironmentVariablesNodeProperty; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Local abstraction to orchestrate remote cleaning. | ||
* | ||
* @author ogondza | ||
*/ | ||
/*package*/ abstract class RemoteCleaner { | ||
|
||
/*package*/ static RemoteCleaner get( | ||
List<Pattern> patterns, | ||
boolean deleteDirs, | ||
String externalDelete, | ||
BuildListener listener, | ||
AbstractBuild<?, ?> build | ||
) { | ||
boolean wipeout = (patterns == null || patterns.isEmpty()) | ||
&& (externalDelete == null || externalDelete.isEmpty()) | ||
; | ||
|
||
if (wipeout) return Wipeout.getInstance(); | ||
|
||
final EnvironmentVariablesNodeProperty properties = build.getBuiltOn() | ||
.getNodeProperties().get(EnvironmentVariablesNodeProperty.class) | ||
; | ||
|
||
return new Cleanup(patterns, deleteDirs, properties, externalDelete, listener); | ||
} | ||
|
||
/** | ||
* Perform the cleanup. | ||
* | ||
* Once this method completes, workspace is ready to be used. | ||
*/ | ||
protected abstract void perform(FilePath workspace) throws IOException, InterruptedException; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2014 Red Hat, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.ws_cleanup; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import hudson.FilePath; | ||
import hudson.FilePath.FileCallable; | ||
import hudson.Util; | ||
import hudson.remoting.VirtualChannel; | ||
|
||
/** | ||
* Cleanup workspace wiping it out completely. | ||
* | ||
* This implementation renames workspace directory and let Jenkins to create | ||
* new one. Old workspace is removed asynchronously. | ||
* | ||
* @author ogondza | ||
*/ | ||
/*package*/ final class Wipeout extends RemoteCleaner { | ||
|
||
private final static Wipeout INSTANCE = new Wipeout(); | ||
|
||
/*package*/ static Wipeout getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
protected void perform(FilePath workspace) throws IOException, InterruptedException { | ||
final FilePath deleteMe = workspace.withSuffix("_ws-cleanup_" + System.currentTimeMillis()); | ||
workspace.renameTo(deleteMe); | ||
deleteMe.actAsync(COMMAND); | ||
} | ||
|
||
private final static Command COMMAND = new Command(); | ||
private final static class Command implements FileCallable<Object> { | ||
public Object invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { | ||
Util.deleteRecursive(f); | ||
return null; | ||
} | ||
} | ||
} |
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
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