diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 07a91eafa0..f95779cbbe 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -436,6 +436,7 @@ public final class FilePath implements Serializable { /** * Writes to this file. * If this file already exists, it will be overwritten. + * If the directory doesn't exist, it will be created. */ public OutputStream write() throws IOException { if(channel==null) @@ -444,7 +445,9 @@ public final class FilePath implements Serializable { final Pipe p = Pipe.createLocalToRemote(); channel.callAsync(new Callable() { public Void call() throws IOException { - FileOutputStream fos = new FileOutputStream(new File(remote)); + File f = new File(remote); + f.getParentFile().mkdirs(); + FileOutputStream fos = new FileOutputStream(f); Util.copyStream(p.getIn(),fos); fos.close(); p.getIn().close();