jenkinsci/jenkins · error · IOException
Failed to create a temporary directory in ${dir}
Error message
Failed to create a temporary directory in ${dir} What it means
Thrown inside CreateTextTempFile.invoke when File.createTempFile fails in the chosen directory (either this FilePath's dir or java.io.tmpdir). The message names the local directory object, distinguishing it from the remote-path wrappers. This is the inner cause that surfaces wrapped by error 37's message.
Source
Thrown at core/src/main/java/hudson/FilePath.java:1681
CreateTextTempFile(boolean inThisDirectory, String prefix, String suffix, String contents) {
this.inThisDirectory = inThisDirectory;
this.prefix = prefix;
this.suffix = suffix;
this.contents = contents;
}
@Override
public String invoke(File dir, VirtualChannel channel) throws IOException {
if (!inThisDirectory)
dir = new File(System.getProperty("java.io.tmpdir"));
else
mkdirs(dir);
File f;
try {
f = File.createTempFile(prefix, suffix, dir);
} catch (IOException e) {
throw new IOException("Failed to create a temporary directory in " + dir, e);
}
try (Writer w = Files.newBufferedWriter(Util.fileToPath(f), Charset.defaultCharset())) {
w.write(contents);
}
return f.getAbsolutePath();
}
}
/**
* Creates a temporary directory inside the directory represented by 'this'
*
* @param prefix
* The prefix string to be used in generating the directory's name;
* must be at least three characters long
* @param suffix
* The suffix string to be used in generating the directory's name; mayView on GitHub (pinned to 2e228ff40b)
Solutions
- Confirm the directory exists and is writable immediately before the call.
- Check disk space and permissions on the target dir or java.io.tmpdir.
- Use a prefix of at least 3 characters with no separators.
- If transient (race with cleanup), retry with a fresh directory.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
File dir = inThisDirectory ? targetDir : new File(System.getProperty("java.io.tmpdir"));
if (!dir.exists() || !dir.canWrite()) throw new IllegalStateException("tmp dir unusable: " + dir); Type guard
null
Try / catch
try {
File.createTempFile(prefix, suffix, dir);
} catch (IOException e) {
// 'Failed to create a temporary directory in' — verify dir writable/not full
} Prevention
- Ensure java.io.tmpdir and the inThisDirectory dir exist and are writable.
- Guard against races with cleanup that removes the dir mid-operation.
- Keep prefix short and valid for the filesystem.
When it happens
Trigger: File.createTempFile fails: directory does not exist (when inThisDirectory=true, mkdirs(dir) is called, but a parent could still be a file); permission denied; disk full; prefix/suffix invalid at the JVM level.
Common situations: Agent workspace directory deleted between mkdirs and createTempFile; java.io.tmpdir on a read-only mount; concurrent cleanup removing the dir; very short prefix.
Related errors
- Failed to mkdirs: ${remote}
- Failed to create a temp file on ${remote}
- Failed to set the timestamp of ${f} to ${timestamp}
- Failed to delete {0}
- Failed to fully read {0}
AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14).
Data as JSON: /api/errors/0df88ac3340dfc67.
Report an issue: GitHub.