diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 07d00a44d006..bfe00cf142ab 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -436,6 +436,14 @@ public static File createTempDir() throws IOException { // https://github.com/jenkinsci/jenkins/pull/3161 ) final Path tempPath; final String tempDirNamePrefix = "jenkins"; + + final Path systemTmpDirectoryPath = Path.of(System.getProperty("java.io.tmpdir")); + if (!systemTmpDirectoryPath.toFile().exists()) { + // In some cases the tmp directory set in the java.io.tmpdir property will not exist and hence will have to + // be created here. + Files.createDirectory(systemTmpDirectoryPath); + } + if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { tempPath = Files.createTempDirectory(tempDirNamePrefix, PosixFilePermissions.asFileAttribute(EnumSet.allOf(PosixFilePermission.class)));