feat: add conditional execution for tasks and commands (#2564)

This commit is contained in:
Valentin Maerten
2026-01-21 23:05:40 +01:00
committed by GitHub
parent da7eb0c855
commit 9bc1efbc47
28 changed files with 444 additions and 0 deletions

View File

@@ -616,6 +616,27 @@ tasks:
- ./deploy.sh
```
#### `if`
- **Type**: `string`
- **Description**: Shell command to conditionally execute the task. If the
command exits with a non-zero code, the task is skipped (not failed).
```yaml
tasks:
# Task only runs in CI environment
deploy:
if: '[ "$CI" = "true" ]'
cmds:
- ./deploy.sh
# Using Go template expressions
build-prod:
if: '{{eq .ENV "production"}}'
cmds:
- go build -ldflags="-s -w" ./...
```
### `dir`
- **Type**: `string`
@@ -812,6 +833,27 @@ tasks:
SERVICE: '{{.ITEM}}'
```
### Conditional Commands
Use `if` to conditionally execute a command. If the shell command exits with a
non-zero code, the command is skipped.
```yaml
tasks:
build:
cmds:
# Only run in production
- cmd: echo "Optimizing for production"
if: '[ "$ENV" = "production" ]'
# Using Go templates
- cmd: echo "Feature enabled"
if: '{{eq .ENABLE_FEATURE "true"}}'
# Inside for loops (evaluated per iteration)
- for: [a, b, c]
cmd: echo "processing {{.ITEM}}"
if: '[ "{{.ITEM}}" != "b" ]'
```
## Shell Options
### Set Options