mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +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) {
|
func run(path, identity string, privileged bool) (int, error) {
|
||||||
dockerClient := docker.New()
|
dockerClient := docker.New()
|
||||||
|
|
||||||
|
// parse the private environment variables
|
||||||
|
envs := getParamMap("DRONE_ENV_")
|
||||||
|
|
||||||
// parse the Drone yml file
|
// parse the Drone yml file
|
||||||
s, err := script.ParseBuildFile(path)
|
s, err := script.ParseBuildFile(script.Inject(path, envs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err.Error())
|
log.Err(err.Error())
|
||||||
return EXIT_STATUS, err
|
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
|
// remove deploy & publish sections
|
||||||
// for now, until I fix bug
|
// for now, until I fix bug
|
||||||
s.Publish = nil
|
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
|
return dir[index+5:], true
|
||||||
}
|
}
|
||||||
|
|
||||||
// getGitOrigin checks the .git origin in an attempt
|
// GetRepoMap returns a map of enivronment variables that
|
||||||
// to correctly determine the code's package path. This
|
// should be injected into the .drone.yml
|
||||||
// is Go-specific, since Go code must exist in
|
func getParamMap(prefix string) map[string]string {
|
||||||
// $GOPATH/src/github.com/{owner}/{name}
|
envs := map[string]string{}
|
||||||
func getGitOrigin(dir string) (path string, ok bool) {
|
|
||||||
// TODO
|
for _, item := range os.Environ() {
|
||||||
return
|
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
|
// prints the time as a human readable string
|
||||||
|
|
Loading…
Reference in a new issue