diff --git a/cli/build.go b/cli/build.go index 1e69359ce..cceb954ce 100644 --- a/cli/build.go +++ b/cli/build.go @@ -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 diff --git a/cli/util.go b/cli/util.go index f98a88c3d..ec4f2de7d 100644 --- a/cli/util.go +++ b/cli/util.go @@ -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