mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-08 15:42:36 +00:00
Avoid calling /bin/env in local backend (#1011)
/bin/env was used to resolve a command name against PATH and pass additional environment variables. All of this can also be achieved using functionality already provided by go's exec lib, which will then internally pass the appropriate arguments to e.g. execve.
This commit is contained in:
parent
061596d802
commit
4879e922c1
1 changed files with 6 additions and 4 deletions
|
@ -49,16 +49,17 @@ func (e *local) Setup(ctx context.Context, proc *types.Config) error {
|
||||||
// Exec the pipeline step.
|
// Exec the pipeline step.
|
||||||
func (e *local) Exec(ctx context.Context, proc *types.Step) error {
|
func (e *local) Exec(ctx context.Context, proc *types.Step) error {
|
||||||
// Get environment variables
|
// Get environment variables
|
||||||
Command := []string{}
|
Env := os.Environ()
|
||||||
for a, b := range proc.Environment {
|
for a, b := range proc.Environment {
|
||||||
if a != "HOME" && a != "SHELL" { // Don't override $HOME and $SHELL
|
if a != "HOME" && a != "SHELL" { // Don't override $HOME and $SHELL
|
||||||
Command = append(Command, a+"="+b)
|
Env = append(Env, a+"="+b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command := []string{}
|
||||||
if proc.Image == constant.DefaultCloneImage {
|
if proc.Image == constant.DefaultCloneImage {
|
||||||
// Default clone step
|
// Default clone step
|
||||||
Command = append(Command, "CI_WORKSPACE="+e.workingdir+"/"+proc.Environment["CI_REPO"])
|
Env = append(Env, "CI_WORKSPACE="+e.workingdir+"/"+proc.Environment["CI_REPO"])
|
||||||
Command = append(Command, "plugin-git")
|
Command = append(Command, "plugin-git")
|
||||||
} else {
|
} else {
|
||||||
// Use "image name" as run command
|
// Use "image name" as run command
|
||||||
|
@ -72,7 +73,8 @@ func (e *local) Exec(ctx context.Context, proc *types.Step) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare command
|
// Prepare command
|
||||||
e.cmd = exec.CommandContext(ctx, "/bin/env", Command...)
|
e.cmd = exec.CommandContext(ctx, Command[0], Command[1:]...)
|
||||||
|
e.cmd.Env = Env
|
||||||
|
|
||||||
// Prepare working directory
|
// Prepare working directory
|
||||||
if proc.Image == constant.DefaultCloneImage {
|
if proc.Image == constant.DefaultCloneImage {
|
||||||
|
|
Loading…
Reference in a new issue