diff --git a/cmd/argoexec/commands/wait.go b/cmd/argoexec/commands/wait.go index 6f0484b1f868..e64def79e064 100644 --- a/cmd/argoexec/commands/wait.go +++ b/cmd/argoexec/commands/wait.go @@ -9,20 +9,25 @@ import ( ) func NewWaitCommand() *cobra.Command { + var captureStderr bool + var command = cobra.Command{ Use: "wait", Short: "wait for main container to finish and save artifacts", Run: func(cmd *cobra.Command, args []string) { - err := waitContainer() + err := waitContainer(captureStderr) if err != nil { log.Fatalf("%+v", err) } }, } + + command.PersistentFlags().BoolVarP(&captureStderr, "capture-stderr", "c", false, "capture stdout and stderr") + return &command } -func waitContainer() error { +func waitContainer(captureStderr bool) error { wfExecutor := initExecutor() defer wfExecutor.HandleError() defer stats.LogStats() @@ -62,7 +67,7 @@ func waitContainer() error { return err } // Capture output script result - err = wfExecutor.CaptureScriptResult() + err = wfExecutor.CaptureScriptResult(captureStderr) if err != nil { wfExecutor.AddError(err) return err diff --git a/workflow/controller/workflowpod.go b/workflow/controller/workflowpod.go index e7dbdb0f3d61..28366d289514 100644 --- a/workflow/controller/workflowpod.go +++ b/workflow/controller/workflowpod.go @@ -317,7 +317,7 @@ func (woc *wfOperationCtx) newInitContainer(tmpl *wfv1.Template) apiv1.Container func (woc *wfOperationCtx) newWaitContainer(tmpl *wfv1.Template) (*apiv1.Container, error) { ctr := woc.newExecContainer(common.WaitContainerName, tmpl) - ctr.Command = []string{"argoexec", "wait"} + ctr.Command = []string{"argoexec", "wait", "--capture-stderr"} switch woc.controller.Config.ContainerRuntimeExecutor { case common.ContainerRuntimeExecutorPNS: ctr.SecurityContext = &apiv1.SecurityContext{ diff --git a/workflow/executor/executor.go b/workflow/executor/executor.go index 56f5e240b537..d453fba5fadf 100644 --- a/workflow/executor/executor.go +++ b/workflow/executor/executor.go @@ -746,8 +746,8 @@ func (we *WorkflowExecutor) GetMainContainerID() (string, error) { return we.mainContainerID, nil } -// CaptureScriptResult will add the stdout of a script template as output result -func (we *WorkflowExecutor) CaptureScriptResult() error { +// CaptureScriptResult will add the stdout (and optionally stderr) of a script template as output result +func (we *WorkflowExecutor) CaptureScriptResult(combinedOutput bool) error { if we.ExecutionControl == nil || !we.ExecutionControl.IncludeScriptOutput { log.Infof("No Script output reference in workflow. Capturing script output ignored") @@ -761,7 +761,7 @@ func (we *WorkflowExecutor) CaptureScriptResult() error { if err != nil { return err } - reader, err := we.RuntimeExecutor.GetOutputStream(mainContainerID, false) + reader, err := we.RuntimeExecutor.GetOutputStream(mainContainerID, combinedOutput) if err != nil { return err }