Skip to content

Ability to use the dotenv key inside included Taskfiles #1075

@apgrucza

Description

@apgrucza

Currently the dotenv key cannot be used inside included Taskfiles. Doing so gives the following error:

Included Taskfiles can't have dotenv declarations. Please, move the dotenv declaration to the main Taskfile

Suppose I have the below structure, where the root Taskfile includes the Taskfiles in the subdirectories:

.
├── app
│   └── Taskfile.yaml
├── deployment
│   └── Taskfile.yaml
└── Taskfile.yaml

I find it useful to be able to have the choice to run Task from either:

  1. the root directory, e.g. task app:build, or
  2. the app subdirectory, e.g. task build

I can't do this and also make use of the dotenv feature. If I place dotenv in the root Taskfile, it will be ignored in case 2. If I place dotenv in the included Taskfile, I get an error in case 1. I'd like dotenv declarations in included files to be processed without error. If the same .env file is referenced in multiple included Taskfiles, this should also not produce an error.

This does raise a question about order of precedence when different .env files are specified across different Taskfiles. Perhaps we could have a rule whereby values in a .env file override values from an included .env file. Or if it's simpler, just return an error if different Taskfiles reference different .env files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions