Skip to content

Commit f9f90af

Browse files
committed
Add --secrets-file option to exec command
1 parent 30d55a2 commit f9f90af

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

drone/exec.go

+26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/drone/drone/queue"
1616

1717
"github.com/codegangsta/cli"
18+
"github.com/joho/godotenv"
1819
)
1920

2021
var execCmd = cli.Command{
@@ -41,6 +42,11 @@ var execCmd = cli.Command{
4142
Usage: "build secrets in KEY=VALUE format",
4243
EnvVar: "DRONE_SECRET",
4344
},
45+
cli.StringFlag{
46+
Name: "secrets-file",
47+
Usage: "build secrets file in KEY=VALUE format",
48+
EnvVar: "DRONE_SECRETS_FILE",
49+
},
4450
cli.StringSliceFlag{
4551
Name: "matrix",
4652
Usage: "build matrix in KEY=VALUE format",
@@ -401,7 +407,27 @@ func getMatrix(c *cli.Context) map[string]string {
401407

402408
// helper function to retrieve secret variables.
403409
func getSecrets(c *cli.Context) []*model.Secret {
410+
404411
var secrets []*model.Secret
412+
413+
if c.String("secrets-file") != "" {
414+
envs, _ := godotenv.Read(c.String("secrets-file"))
415+
for k, v := range envs {
416+
secret := &model.Secret{
417+
Name: k,
418+
Value: v,
419+
Events: []string{
420+
model.EventPull,
421+
model.EventPush,
422+
model.EventTag,
423+
model.EventDeploy,
424+
},
425+
Images: []string{"*"},
426+
}
427+
secrets = append(secrets, secret)
428+
}
429+
}
430+
405431
for _, s := range c.StringSlice("secret") {
406432
parts := strings.SplitN(s, "=", 2)
407433
if len(parts) != 2 {

0 commit comments

Comments
 (0)