Skip to main content
fileexists(path) returns true if a file exists at path, and false otherwise. The path is relative to the playbook’s working directory.

Signature

fileexists(path string) bool

Example

Install dependencies only when a lock file is present, skipping the step entirely when it is not:
task "install" {
  description = "Install Node.js dependencies"
  condition   = fileexists("package-lock.json")
  commands    = ["npm ci"]
}

task "build" {
  description = "Build the frontend"
  depends_on  = [task.install]
  commands    = ["npm run build"]
}
When package-lock.json does not exist, the install task is skipped. build still runs but with no prior install step.

Notes

  • fileexists only returns true for regular files. Passing a path to a directory or other non-regular file returns an error, not false.
  • The path is relative to the playbook’s working directory at evaluation time.
  • Use fileexists in condition to make a task conditional on the presence of a configuration file, lock file, or generated artifact.