diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/PrependToFileStep.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/PrependToFileStep.java index 99161c2d..c6d8b61c 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/PrependToFileStep.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/PrependToFileStep.java @@ -24,6 +24,7 @@ package org.jenkinsci.plugins.pipeline.utility.steps.fs; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Set; @@ -146,9 +147,12 @@ protected FileWrapper run() throws Exception { final FilePath ws = this.getContext().get(FilePath.class); assert ws != null; final FilePath file = ws.child(this.step.getFile()); - if (!file.exists()) { - file.getParent().mkdirs(); + FilePath parent = file.getParent(); + if (!file.exists() && parent != null) { + parent.mkdirs(); file.touch(System.currentTimeMillis()); + } else if (parent == null) { + throw new IOException("No parent path for " + file.getRemote()); } final String content = this.step.getContent(); final String originalContent = file.readToString(); diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStep.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStep.java index c9893a81..e9a29a19 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStep.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStep.java @@ -39,6 +39,7 @@ import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; +import java.io.IOException; import java.util.Collections; import java.util.Set; @@ -143,7 +144,12 @@ protected FileWrapper run() throws Exception { assert ws != null; FilePath file = ws.child(step.getFile()); long timestamp = step.getTimestamp() != null ? step.getTimestamp() : System.currentTimeMillis(); - file.getParent().mkdirs(); + final FilePath parent = file.getParent(); + if (parent != null) { + parent.mkdirs(); + } else { + throw new IOException("No parent path for " + file.getRemote()); + } file.touch(timestamp); return new FileWrapper(file); }