Skip to main content
startswith(str, prefix) returns true if str starts with prefix, and false otherwise.

Signature

startswith(str string, prefix string) bool

Example

Run the full staging pipeline only when the branch is a feature branch:
variable "branch" {
  description = "Current git branch"
  type        = string
}

task "deploy-preview" {
  description = "Deploy a preview environment for feature branches"
  condition   = startswith(var.branch, "feature/")
  commands = [
    "docker build -t myapp:preview-${replace(var.branch, "/", "-")} .",
    "kubectl apply -f k8s/preview/",
  ]
}
The task runs only when branch starts with feature/.

Notes

  • The comparison is case-sensitive. Use lower on both arguments for a case-insensitive check.
  • Returns false when prefix is longer than str.