docs(requires): document enum variable references

This commit is contained in:
Valentin Maerten
2026-01-25 15:27:21 +01:00
parent 58cb143d5b
commit 838ce32cb5
2 changed files with 55 additions and 0 deletions

View File

@@ -1233,6 +1233,51 @@ This is supported only for string variables.
:::
### Using variable references for enum values
Instead of hardcoding enum values, you can reference a variable containing the
allowed values. This is useful when you want to define allowed values once and
reuse them, or when the values are computed dynamically.
Use the `ref` key to reference a variable:
```yaml
version: '3'
vars:
ALLOWED_ENVS: [dev, staging, prod]
tasks:
deploy:
requires:
vars:
- name: ENV
enum:
ref: .ALLOWED_ENVS
cmds:
- echo "Deploying to {{.ENV}}"
```
You can also use template expressions to transform the value:
```yaml
version: '3'
vars:
CONFIG:
sh: cat config.json
tasks:
deploy:
requires:
vars:
- name: ENV
enum:
ref: .CONFIG | fromJson | .allowed_environments
cmds:
- echo "Deploying to {{.ENV}}"
```
### Prompting for missing variables interactively
If you want Task to prompt users for missing required variables instead of

View File

@@ -678,6 +678,16 @@ tasks:
cmds:
- echo "Deploying to {{.ENVIRONMENT}} with log level {{.LOG_LEVEL}}"
- ./deploy.sh
# Requirements with enum from variable reference
reusable-deploy:
requires:
vars:
- name: ENVIRONMENT
enum:
ref: .ALLOWED_ENVS
cmds:
- ./deploy.sh
```
See [Prompting for missing variables interactively](/docs/guide#prompting-for-missing-variables-interactively)