/** * Writes to this file. * If this file already exists, it will be overwritten. * If the directory doesn't exist, it will be created. * * <P> * I/O operation to remote {@link FilePath} happens asynchronously, meaning write operations to the returned * {@link OutputStream} will return without receiving a confirmation from the remote that the write happened. * I/O operations also happens asynchronously from the {@link Channel#call(Callable)} operations, so if * you write to a remote file and then execute {@link Channel#call(Callable)} and try to access the newly copied * file, it might not be fully written yet. * * <p> * */ public OutputStream write() throws IOException, InterruptedException { if(channel==null) { File f = new File(remote).getAbsoluteFile(); mkdirs(f.getParentFile()); return Files.newOutputStream(fileToPath(writing(f))); } return act(new WritePipe()); } private class WritePipe extends SecureFileCallable<OutputStream> {
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { if (!StringUtils.isEmpty(location) && !StringUtils.isEmpty(file.getName())) { listener.getLogger().println("Copying file to "+location); FilePath ws = build.getWorkspace(); if (ws == null) { throw new IllegalStateException("The workspace should be created when setUp method is called"); } if (!ALLOW_FOLDER_TRAVERSAL_OUTSIDE_WORKSPACE && !ws.isDescendant(location)) { listener.error("Rejecting file path escaping base directory with relative path: " + location); // force the build to fail return null; } FilePath locationFilePath = ws.child(location); locationFilePath.getParent().mkdirs(); locationFilePath.copyFrom(file); locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build))); } return new Environment() {}; } };
this.deleteContents(); } else { this.mkdirs();
public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException, InterruptedException { SCM scm = getScm(); if(scm==null) return true; // no SCM FilePath workspace = build.getWorkspace(); if(workspace!=null){ workspace.mkdirs(); } else { throw new AbortException("Cannot checkout SCM, workspace is not defined"); } boolean r = scm.checkout(build, launcher, workspace, listener, changelogFile); if (r) { // Only calcRevisionsFromBuild if checkout was successful. Note that modern SCM implementations // won't reach this line anyway, as they throw AbortExceptions on checkout failure. calcPollingBaseline(build, launcher, listener); } return r; }
private FilePath createBuildDirectory(final FilePath jenkinsBuildRoot) throws IOException, InterruptedException { FilePath directory = jenkinsBuildRoot.child(AFFECTED_FILES_FOLDER_NAME); try { directory.mkdirs(); } catch (IOException exception) { throw new IOException("Can't create directory for workspace files that contain issues: " + directory.getName(), exception); } return directory; }
private FilePath createTemporaryWorkspace(Run<?, ?> run, FilePath workspace, PrintStream logger) throws Exception { logger.println("[WARNING] Performance test: Job workspace contains spaces in path. Virtualenv does not support such path. Creating temporary workspace for virtualenv."); File baseTmpDir = new File(System.getProperty("java.io.tmpdir")); if (baseTmpDir.getAbsolutePath().contains(" ")) { logger.println("[WARNING] Performance test: Temporary folder contains spaces in path."); throw new InvalidPathException(baseTmpDir.getAbsolutePath(), "Virtualenv cannot be installed in workspace that contains spaces in path."); } File tempDir = new File(baseTmpDir.getAbsolutePath(), "perf-test-virtualenv-workspace-" + configJobName(run.getParent().getName())); FilePath tempWorkspace = new FilePath(workspace.getChannel(), tempDir.getAbsolutePath()); tempWorkspace.mkdirs(); return tempWorkspace; }
public int saveSourcesFrom(@Nonnull FilePath dir, @Nonnull String inclusionMask, @Nonnull String exclusionMask) throws IOException, InterruptedException { FilePath d = new FilePath(getSourcesDir()); d.mkdirs(); return dir.copyRecursiveTo(inclusionMask, exclusionMask, d); }
private static Map<String, String> copy(FilePath targetDir, VirtualFile srcDir, String expandedFilter, String expandedExcludes, boolean fingerprint, TaskListener listener, boolean flatten) throws IOException, InterruptedException { targetDir.mkdirs(); // Create target if needed Collection<String> list = srcDir.list(expandedFilter.replace('\\', '/'), expandedExcludes != null ? expandedExcludes.replace('\\', '/') : null, false); Map<String, String> fingerprints = new HashMap<>(); for (String entry : list) { String digest = copyOne(srcDir.child(entry), new FilePath(targetDir, flatten ? entry.replaceFirst(".+/", "") : entry), fingerprint, listener); fingerprints.put(entry, digest); } return fingerprints; }
public int saveClassesFrom(@Nonnull FilePath dir, @Nonnull String fileMask) throws IOException, InterruptedException { FilePath d = new FilePath(getClassesDir()); d.mkdirs(); return dir.copyRecursiveTo(fileMask, d); }
@Override public int copyAll(FilePath srcDir, String filter, String excludes, FilePath targetDir, boolean fingerprintArtifacts) throws IOException, InterruptedException { targetDir.mkdirs(); // Create target if needed FilePath[] list = srcDir.list(filter, excludes, false); for (FilePath file : list) { String tail = file.getRemote().substring(srcDir.getRemote().length()); if (tail.startsWith("\\") || tail.startsWith("/")) tail = tail.substring(1); copyOne(file, new FilePath(targetDir, tail), fingerprintArtifacts); } return list.length; }
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { if (!StringUtils.isEmpty(location) && !StringUtils.isEmpty(file.getName())) { listener.getLogger().println("Copying file to "+location); FilePath locationFilePath = build.getWorkspace().child(location); locationFilePath.getParent().mkdirs(); locationFilePath.copyFrom(file); locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build))); } return new Environment() {}; } };
public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException, InterruptedException { SCM scm = getScm(); if(scm==null) return true; // no SCM FilePath workspace = build.getWorkspace(); workspace.mkdirs(); boolean r = scm.checkout(build, launcher, workspace, listener, changelogFile); calcPollingBaseline(build, launcher, listener); return r; }
public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException, InterruptedException { SCM scm = getScm(); if (scm == null) { return true; // no SCM } FilePath workspace = build.getWorkspace(); workspace.mkdirs(); boolean r = scm.checkout(build, launcher, workspace, listener, changelogFile); calcPollingBaseline(build, launcher, listener); return r; }
public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException, InterruptedException { SCM scm = getScm(); if (scm == null) { return true; // no SCM } FilePath workspace = build.getWorkspace(); workspace.mkdirs(); boolean r = scm.checkout(build, launcher, workspace, listener, changelogFile); calcPollingBaseline(build, launcher, listener); return r; }
public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException, InterruptedException { SCM scm = getScm(); if(scm==null) return true; // no SCM FilePath workspace = build.getWorkspace(); workspace.mkdirs(); boolean r = scm.checkout(build, launcher, workspace, listener, changelogFile); calcPollingBaseline(build, launcher, listener); return r; }
@Override protected FileWrapper run() throws Exception { FilePath file = ws.child(step.getFile()); long timestamp = step.getTimestamp() != null ? step.getTimestamp() : System.currentTimeMillis(); file.getParent().mkdirs(); file.touch(timestamp); return new FileWrapper(file); } }
@Override protected FileWrapper run() throws Exception { FilePath ws = getContext().get(FilePath.class); assert ws != null; FilePath file = ws.child(step.getFile()); long timestamp = step.getTimestamp() != null ? step.getTimestamp() : System.currentTimeMillis(); file.getParent().mkdirs(); file.touch(timestamp); return new FileWrapper(file); } }
@Override protected Void run() throws Exception { FilePath workspace = getContext().get(FilePath.class); workspace.mkdirs(); delegate.perform(getContext().get(Run.class), workspace, getContext().get(Launcher.class), getContext().get(TaskListener.class)); return null; }