Skip to content

Commit

Permalink
cmd support
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX committed Feb 9, 2023
1 parent e88998e commit 4ac9ff4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/container/host_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,12 @@ func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline st
}

func (e *HostEnvironment) Exec(command []string /*cmdline string, */, env map[string]string, user, workdir string) common.Executor {
return e.ExecWithCmdLine(command, "", env, user, workdir)
}

func (e *HostEnvironment) ExecWithCmdLine(command []string, cmdline string, env map[string]string, user, workdir string) common.Executor {
return func(ctx context.Context) error {
if err := e.exec(ctx, command, "" /*cmdline*/, env, user, workdir); err != nil {
if err := e.exec(ctx, command, cmdline, env, user, workdir); err != nil {
select {
case <-ctx.Done():
return fmt.Errorf("this step has been cancelled: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func (s *Step) ShellCommand() string {
case "sh":
shellCommand = "sh -e {0}"
case "cmd":
shellCommand = "%ComSpec% /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
shellCommand = "cmd /D /E:ON /V:OFF /S /C \"CALL \"{0}\"\""
case "powershell":
shellCommand = "powershell -command . '{0}'"
default:
Expand Down
7 changes: 6 additions & 1 deletion pkg/runner/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type stepRun struct {
Step *model.Step
RunContext *RunContext
cmd []string
cmdline string
env map[string]string
}

Expand All @@ -31,6 +32,9 @@ func (sr *stepRun) main() common.Executor {
sr.setupShellCommandExecutor(),
func(ctx context.Context) error {
sr.getRunContext().ApplyExtraPath(ctx, &sr.env)
if he, ok := sr.getRunContext().JobContainer.(*container.HostEnvironment); ok && he != nil {
return he.ExecWithCmdLine(sr.cmd, sr.cmdline, sr.env, "", sr.Step.WorkingDirectory)(ctx)
}
return sr.getRunContext().JobContainer.Exec(sr.cmd, sr.env, "", sr.Step.WorkingDirectory)(ctx)
},
))
Expand Down Expand Up @@ -132,7 +136,8 @@ func (sr *stepRun) setupShellCommand(ctx context.Context) (name, script string,

rc := sr.getRunContext()
scriptPath := fmt.Sprintf("%s/%s", rc.JobContainer.GetActPath(), name)
sr.cmd, err = shellquote.Split(strings.Replace(scCmd, `{0}`, scriptPath, 1))
sr.cmdline = strings.Replace(scCmd, `{0}`, scriptPath, 1)
sr.cmd, err = shellquote.Split(sr.cmdline)

return name, script, err
}
Expand Down

0 comments on commit 4ac9ff4

Please sign in to comment.