Operations
| Operation | Description |
|---|---|
Files.Copy | Copies a file or directory in the build container (a step; relative paths are relative to /workspace). Signature: Copy(string source, string destination, bool optional = false). File source: copied to the destination path (overwritten if it exists); if the destination ends with / or is an existing directory, the file goes into that directory under its own name; otherwise the destination is the target path. Directory source: its contents are copied into the destination, like cp -a src/. dst/: the destination is created if missing, existing contents merge, same-named files are overwritten, and the source directory name is not added (copying a to b gives b/x, not b/a/x). Missing parent directories are created. cp -a preserves modes, times and symlinks. A missing source fails the step ("source not found"); with optional: true it is skipped with an info log. To copy between host and container, use Ando.CopyToContainer and Ando.CopyArtifactsToHost. |
Operation Details
Files.Copy
source
Copies a file or directory in the build container (a step; relative paths are relative to /workspace). Signature: Copy(string source, string destination, bool optional = false). File source: copied to the destination path (overwritten if it exists); if the destination ends with / or is an existing directory, the file goes into that directory under its own name; otherwise the destination is the target path. Directory source: its contents are copied into the destination, like cp -a src/. dst/: the destination is created if missing, existing contents merge, same-named files are overwritten, and the source directory name is not added (copying a to b gives b/x, not b/a/x). Missing parent directories are created. cp -a preserves modes, times and symlinks. A missing source fails the step ("source not found"); with optional: true it is skipped with an info log. To copy between host and container, use Ando.CopyToContainer and Ando.CopyArtifactsToHost.
Files.Copy("config/prod.json", "artifacts/web/config.json");
Files.Copy("public", "artifacts/web", optional: true);Overview
Files.Copy is a step that copies a file or directory inside the build container. Relative paths are relative to /workspace. Missing parent directories of the destination are created, and cp -a preserves modes, times and symlinks.
// File to a file path (overwrites an existing file)
Files.Copy("config/prod.json", "artifacts/web/config.json");
// File into a directory (the destination ends with "/")
Files.Copy("LICENSE", "artifacts/web/");
// Directory contents into a directory; skipped when "public" does not exist
Files.Copy("public", "artifacts/web", optional: true);
Semantics
| Source | Destination |
|---|---|
| File | The target file path. An existing file is overwritten. If the destination ends with / or is an existing directory, the file is copied into that directory under its own name; otherwise the destination is the target path. |
| Directory | The target directory. The contents of the source are copied in, like cp -a src/. dst/. The destination is created if missing; existing contents merge and same-named files are overwritten. The source directory name is never added: copying a to b gives b/x, not b/a/x. |
A missing source fails the step (“source not found”). With optional: true the step succeeds and logs that it was skipped.
Related
- Copy between the host and the container with Ando.CopyToContainer and Ando.CopyArtifactsToHost.
- Pack a directory into a deterministic archive with Archive.Zip or Archive.TarGz.