1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-30 08:06:52 +02: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:
Florian Märkl 2022-07-04 20:27:17 +02:00 committed by GitHub
parent 061596d802
commit 4879e922c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,16 +49,17 @@ func (e *local) Setup(ctx context.Context, proc *types.Config) error {
// Exec the pipeline step.
func (e *local) Exec(ctx context.Context, proc *types.Step) error {
// Get environment variables
Command := []string{}
Env := os.Environ()
for a, b := range proc.Environment {
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 {
// 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")
} else {
// Use "image name" as run command
@ -72,7 +73,8 @@ func (e *local) Exec(ctx context.Context, proc *types.Step) error {
}
// 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
if proc.Image == constant.DefaultCloneImage {