{"record":{"id":"0df88ac3340dfc67","repo":"jenkinsci/jenkins","slug":"failed-to-create-a-temporary-directory-in-dir","errorCode":null,"errorMessage":"Failed to create a temporary directory in ${dir}","messagePattern":"Failed to create a temporary directory in (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/hudson/FilePath.java","lineNumber":1681,"sourceCode":"        CreateTextTempFile(boolean inThisDirectory, String prefix, String suffix, String contents) {\n            this.inThisDirectory = inThisDirectory;\n            this.prefix = prefix;\n            this.suffix = suffix;\n            this.contents = contents;\n        }\n\n        @Override\n        public String invoke(File dir, VirtualChannel channel) throws IOException {\n            if (!inThisDirectory)\n                dir = new File(System.getProperty(\"java.io.tmpdir\"));\n            else\n                mkdirs(dir);\n\n            File f;\n            try {\n                f = File.createTempFile(prefix, suffix, dir);\n            } catch (IOException e) {\n                throw new IOException(\"Failed to create a temporary directory in \" + dir, e);\n            }\n\n            try (Writer w = Files.newBufferedWriter(Util.fileToPath(f), Charset.defaultCharset())) {\n                w.write(contents);\n            }\n\n            return f.getAbsolutePath();\n        }\n    }\n\n    /**\n     * Creates a temporary directory inside the directory represented by 'this'\n     *\n     * @param prefix\n     *      The prefix string to be used in generating the directory's name;\n     *      must be at least three characters long\n     * @param suffix\n     *      The suffix string to be used in generating the directory's name; may","sourceCodeStart":1663,"sourceCodeEnd":1699,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/FilePath.java#L1663-L1699","documentation":"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.","triggerScenarios":"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.","commonSituations":"Agent workspace directory deleted between mkdirs and createTempFile; java.io.tmpdir on a read-only mount; concurrent cleanup removing the dir; very short prefix.","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."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"File dir = inThisDirectory ? targetDir : new File(System.getProperty(\"java.io.tmpdir\"));\nif (!dir.exists() || !dir.canWrite()) throw new IllegalStateException(\"tmp dir unusable: \" + dir);","typeGuard":"null","tryCatchPattern":"try {\n    File.createTempFile(prefix, suffix, dir);\n} catch (IOException e) {\n    // 'Failed to create a temporary directory in' — verify dir writable/not full\n}","preventionTips":["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."],"tags":["temp-file","filesystem","permissions"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}