mirror of
https://github.com/go-task/task.git
synced 2025-06-17 00:17:51 +02:00
Envs should be overridable
System-wide environment variable should have priority. That's how it works for .env files, so this is consistent. Closes #425
This commit is contained in:
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Fixed a bug where an environment in a Taskfile was not always overridable
|
||||||
|
by the system environment
|
||||||
|
([#425](https://github.com/go-task/task/issues/425)).
|
||||||
- Fixed environment from .env files not being available as variables
|
- Fixed environment from .env files not being available as variables
|
||||||
([#379](https://github.com/go-task/task/issues/379)).
|
([#379](https://github.com/go-task/task/issues/379)).
|
||||||
|
|
||||||
|
13
task.go
13
task.go
@ -397,10 +397,19 @@ func getEnviron(t *taskfile.Task) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
environ := os.Environ()
|
environ := os.Environ()
|
||||||
|
|
||||||
for k, v := range t.Env.ToCacheMap() {
|
for k, v := range t.Env.ToCacheMap() {
|
||||||
if s, ok := v.(string); ok {
|
str, isString := v.(string)
|
||||||
environ = append(environ, fmt.Sprintf("%s=%s", k, s))
|
if !isString {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, alreadySet := os.LookupEnv(k); alreadySet {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
environ = append(environ, fmt.Sprintf("%s=%s", k, str))
|
||||||
}
|
}
|
||||||
|
|
||||||
return environ
|
return environ
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user