Declaring Environment Variables
There are two ways to declare environment variables in Taskfile:- Using a
.envfile via thedotenvoption - Using the
envoption directly in the Taskfile
To override an environment variable value at runtime, reference it using
$ENV_NAME format (not {{.ENV_NAME}}). For example, export STAGE=dev will override a value defined in a .env file or env option.Using a .env File
You can specify the
dotenv option at the global or task level.- ~/.env
- test/.env
Taskfile.yml
.HOMEis a magic variable that refers to the home directory of the user.export STAGE=devset explicitly in the environment will override the.envvalue.export MYENV=prodwill not override a value defined directly in the Taskfileenvblock.
Demo and output
Using the env Option
Taskfile.yml
Override a dotenv Variable with env
.env
Taskfile.yml
Demo and output