ability to inject private params into the drone build cli command

This commit is contained in:
Brad Rydzewski 2014-10-12 13:57:29 -07:00
parent 8e84531757
commit 643f811f05
2 changed files with 27 additions and 8 deletions

View file

@ -78,13 +78,21 @@ func buildCommandFunc(c *cli.Context) {
func run(path, identity string, privileged bool) (int, error) {
dockerClient := docker.New()
// parse the private environment variables
envs := getParamMap("DRONE_ENV_")
// parse the Drone yml file
s, err := script.ParseBuildFile(path)
s, err := script.ParseBuildFile(script.Inject(path, envs))
if err != nil {
log.Err(err.Error())
return EXIT_STATUS, err
}
// inject private environment variables into build script
for key, val := range envs {
s.Env = append(s.Env, key+"="+val)
}
// remove deploy & publish sections
// for now, until I fix bug
s.Publish = nil

View file

@ -67,13 +67,24 @@ func getRepoPath(dir string) (path string, ok bool) {
return dir[index+5:], true
}
// getGitOrigin checks the .git origin in an attempt
// to correctly determine the code's package path. This
// is Go-specific, since Go code must exist in
// $GOPATH/src/github.com/{owner}/{name}
func getGitOrigin(dir string) (path string, ok bool) {
// TODO
return
// GetRepoMap returns a map of enivronment variables that
// should be injected into the .drone.yml
func getParamMap(prefix string) map[string]string {
envs := map[string]string{}
for _, item := range os.Environ() {
env := strings.SplitN(item, "=", 2)
if len(env) != 2 {
continue
}
key := env[0]
val := env[1]
if strings.HasPrefix(key, prefix) {
envs[strings.TrimPrefix(key, prefix)] = val
}
}
return envs
}
// prints the time as a human readable string