Skip to main content
file(path) reads the file at path and returns its contents as a UTF-8 string. The path is relative to the playbook’s working directory.

Signature

file(path string) string

Example

Read a version from a dedicated file and use it across the playbook:
computed "version" {
  description = "Application version from the VERSION file"
  expression  = trimspace(file("VERSION"))
}

task "build" {
  description = "Build the binary with the version embedded"
  commands = [
    "go build -ldflags \"-X main.version=${computed.version}\" -o bin/app ./cmd/app",
  ]
}

task "docker-build" {
  description = "Build and tag the Docker image"
  depends_on  = [task.build]
  commands = [
    "docker build -t myapp:${computed.version} .",
    "docker tag myapp:${computed.version} myapp:latest",
  ]
}

Notes

  • If the file does not exist or cannot be read, Errand reports an error at evaluation time.
  • The file contents are read as-is, including any trailing newline. Use trimspace or chomp to strip it.
  • For binary files, use filebase64 to read as base64-encoded string.
  • To check whether a file exists before reading it, use fileexists in a condition.