Delete Local Directory
Removes a folder inside the job directory on the Clarive server, along with everything under it. The removal is recursive and there is no confirmation and no undo.
For a single file, Delete Local File is the safer choice: it refuses to touch a directory, which stops a typo from taking a whole tree with it.
Configuration¶
The op has no form. Its Config tab is a YAML editor where you type the keys yourself, and it reads exactly one:
dir: build/tmp
dir¶
Path of the folder to remove, relative to the job directory. Required. Leave it out and the op stops the job with a message about the missing parameter.
The value expands ${var} placeholders, so dir: ${project}/target works.
The path is always inside the job directory¶
Whatever you type is appended to the job directory. A leading slash does not make the path absolute;
it is stripped and the rest is joined on, so /tmp/work resolves to <job_dir>/tmp/work and not to
/tmp/work.
An empty value is the case to watch. It resolves to the job directory itself, and the op removes the
entire working tree of the running job, checkout included. That is a valid configuration as far as
the op is concerned, so treat a dir built from a stash variable with care: a variable holding an
empty string wipes everything the job has done so far.
A variable that was never set behaves differently. An unresolved placeholder is left in the path as
literal text, so dir: ${never_set} looks for a folder whose name is that placeholder and fails with
Could not find dir.
.. segments are not filtered. dir: ../../tmp/foo resolves above the job directory and removes
whatever it finds there, limited only by the permissions of the account the server runs as. Nothing
checks that the final path stayed inside the job directory. When you mean to remove something outside
the job directory, Run command or local script with an explicit command
says so more clearly.
Failure¶
The folder has to exist and has to be a folder. A path that is missing, or that points at a file,
stops the job with Could not find dir followed by the resolved path.
That makes the op unsuitable as an unconditional cleanup step when the folder is only created on some
runs. Set Error Handling to Ignore Errors on the op's Options tab, or guard it with
IF condition THEN.
Partial removal is not treated as failure. The op stops the job only when nothing at all under the path could be removed. If permissions or a file held open block part of the tree, the rest goes, the op logs its success line and the job carries on with files still sitting there. Do not rely on this op as proof that a path is gone.
What the job log shows¶
One line on success: Successfully deleted directory followed by the full resolved path. The
individual files removed are not listed.
Rollback¶
No rollback behaviour and no copy kept. Deleted is deleted. On a rollback pass the op runs again and
normally fails because the folder is already gone, so clear Run Rollback on the op's Options tab
for any cleanup step.
Combining with other ops¶
Init Job Home already clears the job directory when a job starts, so this op is rarely needed for space. Its real uses are narrower: dropping a build's intermediate output before the tree is packaged, or removing a folder of generated credentials before the job log is archived.
Follow a packaging step with it: build under ${job_dir}/build,
Zip local path the result, then remove the build folder so only the
archive is left to ship with Ship File Remotely.
To check what is inside before removing it, run Load files/items into stash over the same path first and log the count.
For one file rather than a tree, use Delete Local File.
Examples¶
Drop a build's scratch folder once the artifact has been produced.
dir: build/tmp
Remove a per-project working folder, named from the stash.
dir: ${project}/target
Clean up after a checkout of a repository you only needed for its build inputs.
dir: ${project}/vendor