in plugin/step/command/command.go [81:121]
func (s *Step) Execute() error {
var err error
var outFile *os.File
var errFile *os.File
ctx := context.Background()
if s.TimeoutSeconds > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Duration(s.TimeoutSeconds)*time.Second)
defer cancel()
}
if len(s.Command) < 1 {
return fmt.Errorf("empty command specification for %s", TypeName)
}
cmd := exec.CommandContext(ctx, s.Command[0], s.Command[1:]...)
cmd, outFile, errFile, err = setOutputRedirect(s.Output, cmd)
if outFile != nil {
defer outFile.Close()
}
if errFile != nil {
defer errFile.Close()
}
if err != nil {
return err
}
cmd.Dir = s.downloadPath
env := make([]string, 0, len(s.Env))
for _, ev := range s.PassthroughEnv {
for _, eval := range os.Environ() {
if strings.HasPrefix(eval, ev) {
env = append(env, eval)
}
}
}
for k, v := range s.Env {
env = append(env, k+"="+v)
}
cmd.Env = env
return cmd.Run()
}