feat: add conditional execution for tasks and commands by vmaerten · Pull Request #2564 · go-task/task

@vmaerten changed the title feat(if): add conditional execution for tasks and commands feat: add conditional execution for tasks and commands

Dec 11, 2025

@vmaerten vmaerten marked this pull request as ready for review

December 11, 2025 20:58

trulede

Add `if` field to tasks and commands that allows conditional execution
based on a shell command exit code. When the condition returns non-zero,
the task/command is silently skipped (with verbose logging).

- Task-level: skip entire task if condition fails
- Command-level: skip individual command if condition fails
- Supports template variables in conditions
- Works with for loops (condition evaluated per iteration)
- Works with deferred commands
Add comprehensive test cases for:
- Task calls in cmds with if conditions
- Go template functions (eq, ne, and, or)
- Direct template variable evaluation
- CLI variable overrides
- Task-level if with templates
Add comprehensive golden fixture tests for if feature:
- Command-level if (true/false)
- Task-level if (true/false)
- Task calls with if conditions
- Go template functions (eq, ne, and, or)
- Direct template variable evaluation
- CLI variable overrides
- For loops with if conditions

@vmaerten

@vmaerten

andreynering

This was referenced

Jan 21, 2026
Co-authored-by: Andrey Nering <andreynering@users.noreply.github.com>

@vmaerten

@vmaerten

vmaerten added a commit that referenced this pull request

Jan 21, 2026

Copilot AI pushed a commit to libor-m/task that referenced this pull request

Mar 27, 2026
Co-authored-by: libor-m <1497769+libor-m@users.noreply.github.com>

Copilot AI pushed a commit to libor-m/task that referenced this pull request

Mar 27, 2026
Co-authored-by: libor-m <1497769+libor-m@users.noreply.github.com>