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 {
|
||||
return environments.Filesystem(c.StringSlice("environment"))
|
||||
return environments.Parse(c.StringSlice("environment"))
|
||||
}
|
||||
|
||||
// setupRemote helper function to setup the remote from the CLI arguments.
|
||||
|
|
|
@ -3,6 +3,8 @@ package environments
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||
)
|
||||
|
||||
|
@ -10,12 +12,17 @@ type builtin struct {
|
|||
globals []*model.Environ
|
||||
}
|
||||
|
||||
// Filesystem returns a new local registry service.
|
||||
func Filesystem(params []string) model.EnvironService {
|
||||
// Parse returns a EnvironService based on a string slice where key and value are separated by a ":" delimeter.
|
||||
func Parse(params []string) model.EnvironService {
|
||||
var globals []*model.Environ
|
||||
|
||||
for _, item := range params {
|
||||
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]})
|
||||
}
|
||||
return &builtin{globals}
|
||||
|
|
Loading…
Reference in a new issue