Merge pull request #1902 from bradrydzewski/master

put env interpolation behind a flag
This commit is contained in:
Brad Rydzewski 2017-01-18 23:16:46 +07:00 committed by GitHub
commit ff6f16117e

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/url" "net/url"
"os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
@ -93,10 +94,24 @@ func (a *Agent) Run(payload *model.Work, cancel <-chan bool) error {
func (a *Agent) prep(w *model.Work) (*yaml.Config, error) { func (a *Agent) prep(w *model.Work) (*yaml.Config, error) {
envs := toEnv(w) envs := toEnv(w)
envSecrets := map[string]string{}
if os.Getenv("DRONE_INTERPOLATE_SECRETS") != "" {
for _, secret := range w.Secrets {
if w.Verified || secret.SkipVerify {
envSecrets[secret.Name] = secret.Value
}
}
}
var err error var err error
w.Yaml, err = envsubst.Eval(w.Yaml, func(s string) string { w.Yaml, err = envsubst.Eval(w.Yaml, func(s string) string {
env := envs[s] env, ok := envSecrets[s]
if !ok {
env, ok = envs[s]
}
if !ok {
return ""
}
if strings.Contains(env, "\n") { if strings.Contains(env, "\n") {
env = fmt.Sprintf("%q", env) env = fmt.Sprintf("%q", env)
} }