Skip to content

Commit af31122

Browse files
committed
docs: new blog post about if: and required variables prompt
1 parent 1443e2d commit af31122

3 files changed

Lines changed: 145 additions & 0 deletions

File tree

website/.vitepress/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ export default defineConfig({
200200

201201
sidebar: {
202202
'/blog/': [
203+
{
204+
text: '2026',
205+
collapsed: false,
206+
items: [
207+
{
208+
text: 'New `if:` Control and Variable Prompt',
209+
link: '/blog/if-and-variable-prompt'
210+
}
211+
]
212+
},
203213
{
204214
text: '2025',
205215
collapsed: false,
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: New `if:` Control and Variable Prompt
3+
description: Introduction of the `if:` control and required variable prompts.
4+
author: vmaerten
5+
date: 2026-01-24
6+
outline: deep
7+
---
8+
9+
# New `if:` control and interactivity support
10+
11+
<AuthorCard :author="$frontmatter.author" />
12+
13+
The [v3.47.0][release] release is here, and it brings two exciting new features
14+
to Task. Let's take a closer look at them!
15+
16+
## The New `if:` Control
17+
18+
This first feature is simply the second most upvoted issue of all time (!) with
19+
58 :thumbsup:s (!!) at the time of writing.
20+
21+
It introduces the `if:` control, which allow you to conditionally skip the
22+
execution of certain tasks and proceeding. `if:` can be set on a task-level or
23+
command-level, and can be either a Bash command or a Go template expression.
24+
25+
Let me show a couple of examples.
26+
27+
Task-level with Bash expression:
28+
29+
```yaml
30+
version: '3'
31+
32+
tasks:
33+
deploy:
34+
if: '[ "$CI" = "true" ]'
35+
cmds:
36+
- echo "Deploying..."
37+
- ./deploy.sh
38+
```
39+
40+
Command-level with Go template expression:
41+
42+
```yaml
43+
version: '3'
44+
45+
tasks:
46+
conditional:
47+
vars:
48+
ENABLE_FEATURE: "true"
49+
cmds:
50+
- cmd: echo "Feature is enabled"
51+
if: '{{eq .ENABLE_FEATURE "true"}}'
52+
- cmd: echo "Feature is disabled"
53+
if: '{{ne .ENABLE_FEATURE "true"}}'
54+
```
55+
56+
For more details, please check out the [documentation][if-docs].
57+
The [examples][if-examples] from the test suite may be useful too.
58+
59+
::: info
60+
61+
We had similar functionality before, but nothing that perfectly fits this use
62+
case. There were [`sources:`][sources] and [`status:`][status], but those were
63+
meant to check if a task was up-to-date, and [`preconditions:`][preconditions],
64+
but this would halt the execution of the task instead of skipping it.
65+
66+
:::
67+
68+
## Prompt for Required Variables
69+
70+
For backward-compatibility reasons, this feature is disabled by default.
71+
To enable it, either pass `--interactive` flag or add `interactive: true` to
72+
your `.taskrc.yml`.
73+
74+
Once you do that, Task will basically starting prompting you in runtime for any
75+
required variables. In the example below, `NAME` will be prompted at runtime:
76+
77+
```yaml
78+
version: '3'
79+
80+
tasks:
81+
# Simple text input prompt
82+
greet:
83+
desc: Greet someone by name
84+
requires:
85+
vars:
86+
- NAME
87+
cmds:
88+
- echo "Hello, {{.NAME}}!"
89+
```
90+
91+
If a given variable has an enum, Task will actually show a selection menu so you
92+
can choose the right option instead of typing:
93+
94+
```yaml
95+
version: '3'
96+
97+
tasks:
98+
# Enum selection (dropdown menu)
99+
deploy:
100+
desc: Deploy to an environment
101+
requires:
102+
vars:
103+
- name: ENVIRONMENT
104+
enum: [dev, staging, prod]
105+
cmds:
106+
- echo "Deploying to {{.ENVIRONMENT}}..."
107+
```
108+
109+
Once again, check out the [documentation][prompt-docs] for more details, and the
110+
[prompt examples][prompt-examples] from the test suite.
111+
112+
## Feedback
113+
114+
Let's us know if you have any feedback! You can find us on our
115+
[Discord server][discord].
116+
117+
[release]: https://github.com/go-task/task/releases/tag/v3.47.0
118+
[vmaerten]: https://github.com/vmaerten
119+
[sources]: https://taskfile.dev/docs/guide#by-fingerprinting-locally-generated-files-and-their-sources
120+
[status]: https://taskfile.dev/docs/guide#using-programmatic-checks-to-indicate-a-task-is-up-to-date
121+
[preconditions]: https://taskfile.dev/docs/guide#using-programmatic-checks-to-cancel-the-execution-of-a-task-and-its-dependencies
122+
[if-docs]: https://taskfile.dev/docs/guide#conditional-execution-with-if
123+
[if-examples]: https://github.com/go-task/task/blob/main/testdata/if/Taskfile.yml
124+
[prompt-docs]: https://taskfile.dev/docs/guide#prompting-for-missing-variables-interactively
125+
[prompt-examples]: https://github.com/go-task/task/blob/main/testdata/interactive_vars/Taskfile.yml
126+
[discord]: https://discord.com/invite/6TY36E39UK

website/src/blog/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ title: Blog
33
description: Latest news and updates from the Task team
44
---
55

6+
<BlogPost
7+
title="New `if:` Control and Variable Prompt"
8+
url="/blog/if-and-variable-prompt"
9+
date="2026-01-24"
10+
author="vmaerten"
11+
description="The v3.47.0 release is here, and it brings two exciting new features to Task. Let's take a closer look at them!"
12+
:tags="['new-features', 'variables']"
13+
/>
14+
615
<BlogPost
716
title="Announcing Built-in Core Utilities for Windows"
817
url="/blog/windows-core-utils"

0 commit comments

Comments
 (0)