Skip to content
Browse files
[JENKINS-27152] Introduce common API WorkspaceList.tempDir.
  • Loading branch information
jglick committed Feb 26, 2016
1 parent 679da79 commit 307bfc17385c14aefcb623ccc3e7144e4f01e2a3
@@ -27,6 +27,7 @@
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.Util;
import hudson.slaves.WorkspaceList;
import java.util.ArrayList;
import java.util.Date;
@@ -89,6 +90,7 @@ public static void invoke() {
listener.getLogger().println("Deleting " + ws + " on " + node.getDisplayName());
try {
} catch (IOException x) {
x.printStackTrace(listener.error("Failed to delete " + ws + " on " + node.getDisplayName()));
} catch (InterruptedException x) {
@@ -26,6 +26,7 @@
import hudson.FilePath;
import hudson.Functions;
import hudson.model.Computer;
import hudson.model.DirectoryBrowserSupport;

import java.util.Date;
@@ -283,6 +284,25 @@ public void release() {

* Locates a conventional temporary directory to be associated with a workspace.
* <p>This directory is suitable for temporary files to be deleted later in the course of a build,
* or caches and local repositories which should persist across builds done in the same workspace.
* (If multiple workspaces are present for a single job built concurrently, via {@link #allocate(FilePath)}, each will get its own temporary directory.)
* <p>It may also be used for security-sensitive files which {@link DirectoryBrowserSupport} ought not serve,
* acknowledging that these will be readable by builds of other jobs done on the same node.
* <p>Each plugin using this directory is responsible for specifying sufficiently unique subdirectory/file names.
* {@link FilePath#createTempFile} may be used for this purpose if desired.
* <p>The resulting directory may not exist; you may call {@link FilePath#mkdirs} on it if you need it to.
* It may be deleted alongside the workspace itself during cleanup actions.
* @param ws a directory such as a build workspace
* @return a sibling directory, for example {@code …/something@tmp} for {@code …/something}
* @since TODO
public static FilePath tempDir(FilePath ws) {
return ws.sibling(ws.getName() + COMBINATOR + "tmp");

private static final Logger LOGGER = Logger.getLogger(WorkspaceList.class.getName());

@@ -28,6 +28,7 @@
import hudson.remoting.VirtualChannel;
import hudson.scm.NullSCM;
import hudson.slaves.DumbSlave;
import hudson.slaves.WorkspaceList;
import hudson.util.StreamTaskListener;

@@ -180,6 +181,19 @@

public void deleteTemporaryDirectory() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
FilePath ws = createOldWorkspaceOn(r.jenkins, p);
FilePath tmp = WorkspaceList.tempDir(ws);
tmp.child("stuff").write("content", null);
createOldWorkspaceOn(r.createOnlineSlave(), p);
assertFalse("temporary directory should be cleaned up as well", tmp.exists());

private FilePath createOldWorkspaceOn(Node slave, FreeStyleProject p) throws Exception {
FreeStyleBuild b1 = r.assertBuildStatusSuccess(p.scheduleBuild2(0));

0 comments on commit 307bfc1

Please sign in to comment.