mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-25 09:50:31 +00:00
Merge pull request #1668 from frapposelli/add-secrets-file-option
Add `--secrets-file` option to exec command
This commit is contained in:
commit
2530f8723f
1 changed files with 26 additions and 0 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/drone/drone/queue"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var execCmd = cli.Command{
|
||||
|
@ -41,6 +42,11 @@ var execCmd = cli.Command{
|
|||
Usage: "build secrets in KEY=VALUE format",
|
||||
EnvVar: "DRONE_SECRET",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "secrets-file",
|
||||
Usage: "build secrets file in KEY=VALUE format",
|
||||
EnvVar: "DRONE_SECRETS_FILE",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "matrix",
|
||||
Usage: "build matrix in KEY=VALUE format",
|
||||
|
@ -401,7 +407,27 @@ func getMatrix(c *cli.Context) map[string]string {
|
|||
|
||||
// helper function to retrieve secret variables.
|
||||
func getSecrets(c *cli.Context) []*model.Secret {
|
||||
|
||||
var secrets []*model.Secret
|
||||
|
||||
if c.String("secrets-file") != "" {
|
||||
envs, _ := godotenv.Read(c.String("secrets-file"))
|
||||
for k, v := range envs {
|
||||
secret := &model.Secret{
|
||||
Name: k,
|
||||
Value: v,
|
||||
Events: []string{
|
||||
model.EventPull,
|
||||
model.EventPush,
|
||||
model.EventTag,
|
||||
model.EventDeploy,
|
||||
},
|
||||
Images: []string{"*"},
|
||||
}
|
||||
secrets = append(secrets, secret)
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range c.StringSlice("secret") {
|
||||
parts := strings.SplitN(s, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
|
|
Loading…
Reference in a new issue