Environment Variables
How to use environment variables in Taskfile
Environment variable in Taskfile
There are two ways to declare environment variables in Taskfile:
- Using a
.env
file via thedotnet
option in the Taskfile. - Using
env
option in the Taskfile.
If you want to override the value of an environment variable, you have to reference it using the $ENV_NAME
format in the Taskfile, not {{.ENV_NAME}}
. You can refer below for more details.
export STAGE=dev
will override the value ofSTAGE
defined in.env
file orenv
option in the Taskfile.
Using .env file
You can specify dotnet
option in global or task level.
Taskfile.yml
.env
.env
Assume you have the following content:
.HOME
is a magic variable that refers to the home directory of the user.export STAGE=dev
, if set explicitly in the environment, it will override the value ofSTAGE
defined in.env
file.- but if you set
export MYENV=prod
, it will not override the value ofMYENV
defined in Taskfile.
- but if you set