@@ -100,6 +100,10 @@ func (in *stackRunController) toExecutable(ctx context.Context, step *gqlclient.
100100 // ensuring they have completed all work.
101101 in .wg .Add (1 )
102102
103+ toolWriters := make ([]io.WriteCloser , 0 )
104+ modifier := in .tool .Modifier (step .Stage )
105+ args := step .Args
106+ env := in .stackRun .Env ()
103107 consoleWriter := sink .NewConsoleWriter (
104108 ctx ,
105109 in .consoleClient ,
@@ -115,29 +119,35 @@ func (in *stackRunController) toExecutable(ctx context.Context, step *gqlclient.
115119 )... ,
116120 )
117121
118- var toolWriters []io.WriteCloser
119- modifier := in .tool .Modifier (step .Stage )
120- args := step .Args
121- env := in .stackRun .Env ()
122122 if modifier != nil {
123123 args = modifier .Args (args )
124124 env = modifier .Env (env )
125125 toolWriters = modifier .WriteCloser ()
126126 }
127127
128- return exec . NewExecutable (
129- step . Cmd ,
130- append (
131- in . execOptions ,
132- exec .WithDir (in .execWorkDir ()),
133- exec .WithEnv (env ),
134- exec .WithArgs (args ),
135- exec .WithID (step .ID ),
136- exec .WithOutputSinks (append (toolWriters , consoleWriter )... ),
137- exec .WithHook (v1 .LifecyclePreStart , in .preExecHook (step .Stage , step .ID )),
138- exec .WithHook (v1 .LifecyclePostStart , in .postExecHook (step .Stage )),
139- ) ... ,
128+ // base executable options
129+ options := in . execOptions
130+ options = append (
131+ options ,
132+ exec .WithDir (in .execWorkDir ()),
133+ exec .WithEnv (env ),
134+ exec .WithArgs (args ),
135+ exec .WithID (step .ID ),
136+ exec .WithOutputSinks (append (toolWriters , consoleWriter )... ),
137+ exec .WithHook (v1 .LifecyclePreStart , in .preExecHook (step .Stage , step .ID )),
138+ exec .WithHook (v1 .LifecyclePostStart , in .postExecHook (step .Stage )),
139+ exec . WithOutputAnalyzer ( exec . NewKeywordDetector ()) ,
140140 )
141+
142+ // Add a custom run step output analyzer for the destroy stage to increase
143+ // a chance of detecting errors during execution. On occasion executable can
144+ // return exit code 0 even though there was a fatal error during execution.
145+ // TODO: use destroy stage
146+ // if step.Stage == gqlclient.StepStageApply {
147+ // options = append(options, exec.WithOutputAnalyzer(exec.NewKeywordDetector()))
148+ //}
149+
150+ return exec .NewExecutable (step .Cmd , options ... )
141151}
142152
143153func (in * stackRunController ) completeStackRun (status gqlclient.StackStatus , stackRunErr error ) error {
0 commit comments