Skip to content

Commit

Permalink
cli exec: let override existing environment values but print a warn…
Browse files Browse the repository at this point in the history
…ing (#3140)

Co-authored-by: Anbraten <anton@ju60.de>
  • Loading branch information
6543 and anbraten authored Jan 12, 2024
1 parent 8aed3a3 commit a5fa810
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a5fa810

Please sign in to comment.