-
-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
passing environment variables to task via command directly on windows #203
Comments
You can set the env in your Taskfile from variables (or environment when no variables are set) using: version: '2'
env:
CONFIG: '{{.CONFIG | default "Debug"}}'
tasks:
print:
cmds:
- echo $CONFIG Then you should be able to run |
OK, that makes sense. didn't know could write in this way I'll give a try! thanks again |
I have tried above approach, and generally it would work well. For example, # https://taskfile.org
version: '2'
env:
CONFIG: '{{.CONFIG | default "Debug"}}'
tasks:
foo:
deps: [bar]
cmds:
- echo $CONFIG Configuration for task foo
- task: bar
vars:
CONFIG: "{{.CONFIG}}"
silent: true
bar:
cmds:
- echo $CONFIG Configuration for task bar
silent: true And when running
Where first time of executing bar is under Debug configuration. @smyrman do you have any means to work around this? |
IMHO, this may be caused by env is evaluated per time task is called? |
This looks like a bug to me. @andreynering? From what I can tell, the variable is passed on to the specific task when passed on the CLI, and not to the global vars or env. In addition, I am surprised that the env is re-evaluated for each task -- is this intentional? I tried a few different variants, this works, but defeats the purpose of a global # https://taskfile.org
version: '2'
env:
CONFIG: '{{.CONFIG | default "Debug"}}'
tasks:
foo:
deps:
- task: bar
vars:
CONFIG: '{{.CONFIG}}'
cmds:
- echo $CONFIG Configuration for task foo
- task: bar
vars:
CONFIG: '{{.CONFIG}}'
silent: true
bar:
cmds:
- echo $CONFIG Configuration for task bar
silent: true
This does not: # https://taskfile.org
version: '2'
vars:
CONFIG: '{{.CONFIG | default "Debug"}}'
tasks:
foo:
env:
CONFIG: '{{.CONFIG}}'
deps:
- task: bar
cmds:
- echo $CONFIG Configuration for task foo
- task: bar
silent: true
bar:
env:
CONFIG: '{{.CONFIG}}'
cmds:
- echo $CONFIG Configuration for task bar
silent: true
|
Couple of things to discuss here. First: yes, it's by design that all variables are evaluated on each task run, even global ones. Perhaps that can change in the future, but it's how it works today. Second: I just pushed an improvement that will allow you to set global variables through the CLI (#192, f0768b3). I think that's enough to allow your use case for now. Third: the idea of allow setting an environment variable through the CLI by prepending |
Thank you guys for sharing those information.
I see this is the design right now.
So I will use the way provided by @smyrman to accomplish what i want, and also I'll try the global variable feature :P
If i have spare time I would like to submit a PR. |
@LittleC That's great. 🙂 |
Is this working like this? I tried it with both code above, and the results are the same for Version 3 now. |
For Mac, I could pass environment variables like this
CONFIG=Debug task print
,but for windows, I have to do
$env:CONFIG='Debug'; task print; Remove-Item Env:\CONFIG
in powershell, becausetask print CONFIG=Release
will just parse that asvars
rather thanenv
.I'm wondering if it is possible to provide a way to pass env variable directly in one command like
task print $CONFIG=Debug VAR=test
, for which$
will be recognized as envvars
like currentOr any other ideas? Open for discussion.
The text was updated successfully, but these errors were encountered: