mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-03 06:08:42 +00:00
Ignore items from WOODPECKER_ENVIRONMENT only containing a key and no value (#781)
* fix 761 * refactor: rename to match what it does & log ignore case
This commit is contained in:
parent
dde0678246
commit
c4960cdd2c
2 changed files with 10 additions and 3 deletions
|
@ -173,7 +173,7 @@ func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
|
func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
|
||||||
return environments.Filesystem(c.StringSlice("environment"))
|
return environments.Parse(c.StringSlice("environment"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupRemote helper function to setup the remote from the CLI arguments.
|
// setupRemote helper function to setup the remote from the CLI arguments.
|
||||||
|
|
|
@ -3,6 +3,8 @@ package environments
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,12 +12,17 @@ type builtin struct {
|
||||||
globals []*model.Environ
|
globals []*model.Environ
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filesystem returns a new local registry service.
|
// Parse returns a EnvironService based on a string slice where key and value are separated by a ":" delimeter.
|
||||||
func Filesystem(params []string) model.EnvironService {
|
func Parse(params []string) model.EnvironService {
|
||||||
var globals []*model.Environ
|
var globals []*model.Environ
|
||||||
|
|
||||||
for _, item := range params {
|
for _, item := range params {
|
||||||
kvPair := strings.SplitN(item, ":", 2)
|
kvPair := strings.SplitN(item, ":", 2)
|
||||||
|
if len(kvPair) != 2 {
|
||||||
|
// ignore items only containing a key and no value
|
||||||
|
log.Warn().Msgf("key '%s' has no value, will be ignored", kvPair[0])
|
||||||
|
continue
|
||||||
|
}
|
||||||
globals = append(globals, &model.Environ{Name: kvPair[0], Value: kvPair[1]})
|
globals = append(globals, &model.Environ{Name: kvPair[0], Value: kvPair[1]})
|
||||||
}
|
}
|
||||||
return &builtin{globals}
|
return &builtin{globals}
|
||||||
|
|
Loading…
Reference in a new issue