From a5fa810bcc42d9dd115afb39157720221e9c53b2 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 12 Jan 2024 15:24:30 +0100 Subject: [PATCH] `cli exec`: let override existing environment values but print a warning (#3140) Co-authored-by: Anbraten --- cli/exec/exec.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cli/exec/exec.go b/cli/exec/exec.go index b78a1a0a5..38394357c 100644 --- a/cli/exec/exec.go +++ b/cli/exec/exec.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/drone/envsubst" + "github.com/rs/zerolog/log" "github.com/urfave/cli/v2" "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") { envs := strings.SplitN(env, "=", 2) - droneEnv[envs[0]] = envs[1] - if _, exists := environ[envs[0]]; exists { - // don't override existing values - continue + pipelineEnv[envs[0]] = envs[1] + if oldVar, exists := environ[envs[0]]; exists { + // override existing values, but print a warning + log.Warn().Msgf("environment variable '%s' had value '%s', but got overwritten", envs[0], oldVar) } 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.WithSecret(secrets...), - compiler.WithEnviron(droneEnv), + compiler.WithEnviron(pipelineEnv), ).Compile(conf) if err != nil { return err