mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-26 21:44:44 +00:00
cli exec
: let override existing environment values but print a warning (#3140)
Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
8aed3a375d
commit
a5fa810bcc
1 changed files with 7 additions and 6 deletions
|
@ -25,6 +25,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/drone/envsubst"
|
"github.com/drone/envsubst"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/cli/common"
|
"go.woodpecker-ci.org/woodpecker/v2/cli/common"
|
||||||
|
@ -121,13 +122,13 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
droneEnv := make(map[string]string)
|
pipelineEnv := make(map[string]string)
|
||||||
for _, env := range c.StringSlice("env") {
|
for _, env := range c.StringSlice("env") {
|
||||||
envs := strings.SplitN(env, "=", 2)
|
envs := strings.SplitN(env, "=", 2)
|
||||||
droneEnv[envs[0]] = envs[1]
|
pipelineEnv[envs[0]] = envs[1]
|
||||||
if _, exists := environ[envs[0]]; exists {
|
if oldVar, exists := environ[envs[0]]; exists {
|
||||||
// don't override existing values
|
// override existing values, but print a warning
|
||||||
continue
|
log.Warn().Msgf("environment variable '%s' had value '%s', but got overwritten", envs[0], oldVar)
|
||||||
}
|
}
|
||||||
environ[envs[0]] = envs[1]
|
environ[envs[0]] = envs[1]
|
||||||
}
|
}
|
||||||
|
@ -206,7 +207,7 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
|
||||||
),
|
),
|
||||||
compiler.WithMetadata(metadata),
|
compiler.WithMetadata(metadata),
|
||||||
compiler.WithSecret(secrets...),
|
compiler.WithSecret(secrets...),
|
||||||
compiler.WithEnviron(droneEnv),
|
compiler.WithEnviron(pipelineEnv),
|
||||||
).Compile(conf)
|
).Compile(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue