mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 00:46:30 +00:00
ability to inject private params into the drone build
cli command
This commit is contained in:
parent
8e84531757
commit
643f811f05
2 changed files with 27 additions and 8 deletions
10
cli/build.go
10
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
|
||||
|
|
25
cli/util.go
25
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
|
||||
|
|
Loading…
Reference in a new issue