diff --git a/pipeline/backend/local/local.go b/pipeline/backend/local/local.go index 8f07d1f73..3ec663bf1 100644 --- a/pipeline/backend/local/local.go +++ b/pipeline/backend/local/local.go @@ -4,6 +4,7 @@ import ( "context" "encoding/base64" "io" + "io/ioutil" "os" "os/exec" "strings" @@ -13,8 +14,9 @@ import ( ) type local struct { - cmd *exec.Cmd - output io.ReadCloser + cmd *exec.Cmd + output io.ReadCloser + workingdir string } // make sure local implements Engine @@ -34,7 +36,9 @@ func (e *local) IsAvailable() bool { } func (e *local) Load() error { - return nil + dir, err := ioutil.TempDir("", "woodpecker-local-*") + e.workingdir = dir + return err } // Setup the pipeline environment. @@ -60,7 +64,7 @@ func (e *local) Exec(ctx context.Context, proc *types.Step) error { if proc.Image == defaultCloneImage { // Default clone step - Command = append(Command, "CI_WORKSPACE=/tmp/woodpecker/"+proc.Environment["CI_REPO"]) + Command = append(Command, "CI_WORKSPACE="+e.workingdir+"/"+proc.Environment["CI_REPO"]) Command = append(Command, "plugin-git") } else { // Use "image name" as run command @@ -78,12 +82,14 @@ func (e *local) Exec(ctx context.Context, proc *types.Step) error { // Prepare working directory if proc.Image == defaultCloneImage { - e.cmd.Dir = "/tmp/woodpecker/" + proc.Environment["CI_REPO_OWNER"] + e.cmd.Dir = e.workingdir + "/" + proc.Environment["CI_REPO_OWNER"] } else { - e.cmd.Dir = "/tmp/woodpecker/" + proc.Environment["CI_REPO"] + e.cmd.Dir = e.workingdir + "/" + proc.Environment["CI_REPO"] + } + err := os.MkdirAll(e.cmd.Dir, 0o700) + if err != nil { + return err } - _ = os.MkdirAll(e.cmd.Dir, 0o700) - // Get output and redirect Stderr to Stdout e.output, _ = e.cmd.StdoutPipe() e.cmd.Stderr = e.cmd.Stdout