diff --git a/cmd/drone-server/server.go b/cmd/drone-server/server.go index cd8631fd9..9a6d69848 100644 --- a/cmd/drone-server/server.go +++ b/cmd/drone-server/server.go @@ -133,6 +133,10 @@ var flags = []cli.Flag{ EnvVar: "DRONE_VOLUME", Name: "volume", }, + cli.StringSliceFlag{ + EnvVar: "DRONE_ENVIRONMENT", + Name: "environment", + }, cli.StringSliceFlag{ EnvVar: "DRONE_NETWORK", Name: "network", diff --git a/cmd/drone-server/setup.go b/cmd/drone-server/setup.go index d85cbec2f..4fb8a844c 100644 --- a/cmd/drone-server/setup.go +++ b/cmd/drone-server/setup.go @@ -21,6 +21,7 @@ import ( "github.com/dimfeld/httptreemux" "github.com/laszlocph/woodpecker/cncd/queue" "github.com/laszlocph/woodpecker/model" + "github.com/laszlocph/woodpecker/plugins/environments" "github.com/laszlocph/woodpecker/plugins/registry" "github.com/laszlocph/woodpecker/plugins/secrets" "github.com/laszlocph/woodpecker/remote" @@ -63,7 +64,7 @@ func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService { } func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService { - return nil + return environments.Filesystem(c.StringSlice("environment")) } func setupPubsub(c *cli.Context) {} diff --git a/plugins/environments/filesystem.go b/plugins/environments/filesystem.go new file mode 100644 index 000000000..4298e4913 --- /dev/null +++ b/plugins/environments/filesystem.go @@ -0,0 +1,25 @@ +package environments + +import ( + "github.com/laszlocph/woodpecker/model" + "strings" +) + +type builtin struct { + globals []*model.Environ +} + +// New returns a new local registry service. +func Filesystem(params []string) model.EnvironService { + var globals []*model.Environ + + for _, item := range params { + kvpair := strings.SplitN(item, ":", 2) + globals = append(globals, &model.Environ{Name: kvpair[0], Value: kvpair[1]}) + } + return &builtin{globals} +} + +func (b *builtin) EnvironList(repo *model.Repo) ([]*model.Environ, error) { + return b.globals, nil +} diff --git a/plugins/environments/filesystem_test.go b/plugins/environments/filesystem_test.go new file mode 100644 index 000000000..d4fcbc9f9 --- /dev/null +++ b/plugins/environments/filesystem_test.go @@ -0,0 +1 @@ +package environments