mirror of
https://github.com/go-task/task.git
synced 2026-07-09 06:55:14 +00:00
feat: experiment taskfile envs take precedence over os envs (#1633)
* feat: experiment taskfile envs take precedence over os envs * fix test * fix typo Co-authored-by: Andrey Nering <andrey@nering.com.br> * docs: add p about default --------- Co-authored-by: Andrey Nering <andrey@nering.com.br>
This commit is contained in:
70
website/docs/experiments/env_precedence.mdx
Normal file
70
website/docs/experiments/env_precedence.mdx
Normal file
@@ -0,0 +1,70 @@
|
||||
---
|
||||
draft: false # Hide in production
|
||||
slug: '/experiments/env-precedence'
|
||||
---
|
||||
|
||||
# Env Precedence (#1038)
|
||||
|
||||
:::caution
|
||||
|
||||
All experimental features are subject to breaking changes and/or removal _at any
|
||||
time_. We strongly recommend that you do not use these features in a production
|
||||
environment. They are intended for testing and feedback only.
|
||||
|
||||
:::
|
||||
|
||||
:::warning
|
||||
|
||||
This experiment breaks the following functionality:
|
||||
|
||||
- environment variable will take precedence over OS environment variables
|
||||
|
||||
:::
|
||||
|
||||
:::info
|
||||
|
||||
To enable this experiment, set the environment variable: `TASK_X_ENV_PRECEDENCE=1`.
|
||||
Check out [our guide to enabling experiments ][enabling-experiments] for more
|
||||
information.
|
||||
|
||||
:::
|
||||
|
||||
Before this experiment, the OS variable took precedence over the task environment variable. This experiment changes the precedence to make the task environment variable take precedence over the OS variable.
|
||||
|
||||
Consider the following example:
|
||||
|
||||
```yml
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
env:
|
||||
KEY: 'other'
|
||||
cmds:
|
||||
- echo "$KEY"
|
||||
```
|
||||
Running `KEY=some task` before this experiment, the output would be `some`, but after this experiment, the output would be `other`.
|
||||
|
||||
If you still want to get the OS variable, you can use the template function env like follow : `{{env "OS_VAR"}}`.
|
||||
|
||||
```yml
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
env:
|
||||
KEY: 'other'
|
||||
cmds:
|
||||
- echo "$KEY"
|
||||
- echo {{env "KEY"}}
|
||||
```
|
||||
Running `KEY=some task`, the output would be `other` and `some`.
|
||||
|
||||
Like other variables/envs, you can also fall back to a given value using the default template function:
|
||||
```yml
|
||||
MY_ENV: '{{.MY_ENV | default "fallback"}}'
|
||||
```
|
||||
|
||||
{/* prettier-ignore-start */}
|
||||
[enabling-experiments]: ./experiments.mdx#enabling-experiments
|
||||
{/* prettier-ignore-end */}
|
||||
Reference in New Issue
Block a user