Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-12823] Clean up temporary config files at the very end…
…, not before post-build
- Loading branch information
Showing
5 changed files
with
235 additions
and
209 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/org/jenkinsci/plugins/configfiles/buildwrapper/CleanTempFilesAction.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,26 @@ | ||
package org.jenkinsci.plugins.configfiles.buildwrapper; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.InvisibleAction; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Temporal action to transport information about t files to be deleted to the CleanTempFilesRunListener. | ||
* | ||
* @author Dominik Bartholdi (imod) | ||
* @see org.jenkinsci.plugins.configfiles.buildwrapper.CleanTempFilesRunListener | ||
*/ | ||
public class CleanTempFilesAction extends InvisibleAction { | ||
|
||
/** | ||
* list of the temp files to be removed - never <code>null</code> | ||
*/ | ||
public List<FilePath> tempFiles; | ||
|
||
public CleanTempFilesAction(List<FilePath> tempFiles) { | ||
this.tempFiles = tempFiles == null ? new ArrayList<FilePath>() : tempFiles; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/jenkinsci/plugins/configfiles/buildwrapper/CleanTempFilesRunListener.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,40 @@ | ||
/** | ||
* | ||
*/ | ||
package org.jenkinsci.plugins.configfiles.buildwrapper; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.model.TaskListener; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.listeners.RunListener; | ||
|
||
|
||
/** | ||
* Removes the temporarily created files at 'onComplete()' of each build, doing it at this state, ensures the files are available also for publishers. | ||
* | ||
* @author Dominik Bartholdi (imod) | ||
*/ | ||
@Extension | ||
public class CleanTempFilesRunListener extends RunListener<AbstractBuild<?, ?>> { | ||
|
||
@Override | ||
public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) { | ||
CleanTempFilesAction action = build.getAction(CleanTempFilesAction.class); | ||
|
||
if (action != null) { | ||
for (FilePath fp : action.tempFiles) { | ||
try { | ||
if (fp != null && fp.exists()) { | ||
fp.delete(); | ||
} | ||
} catch (Exception e) { | ||
listener.getLogger().println("[WARN] failed to delete temp file: " + fp.getRemote()); | ||
} | ||
} | ||
// remove the action, there is nothing we want to persist on the build | ||
build.getActions().remove(action); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.