Skip to main content
You can use if-else conditions in Taskfile to control the execution of tasks based on certain conditions. Taskfile uses Go’s template engine, so conditions follow Go template syntax.
Taskfile.yaml
version: '3'
tasks:
  example:
    summary: |
      An example task that uses if-else conditions
    vars:
      CONDITION: true
    cmds:
      - echo "Starting task..."
      - |
        {{ if .CONDITION }}
          echo "Condition is true, executing this block"
        {{ else }}
          echo "Condition is false, executing this block"
        {{ end }}
      - echo "Task completed"
Demo and Output
ubuntu@touted-mite:~$ task example
task: [example] echo "Starting task..."
Starting task...
task: [example]
  echo "Condition is true, executing this block"

Condition is true, executing this block
task: [example] echo "Task completed"
Task completed

Build docs developers (and LLMs) love