Taskfile.yaml
Demo and Output
Use Go template if-else conditions in Taskfile to control task execution based on variable values.
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"
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