mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
Merge pull request #1902 from bradrydzewski/master
put env interpolation behind a flag
This commit is contained in:
commit
ff6f16117e
1 changed files with 16 additions and 1 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue