@@ -45,6 +45,11 @@ type Executor struct {
45
45
preCreatedWorkingDir string
46
46
}
47
47
48
+ var (
49
+ ErrStepExit = errors .New ("executor step requested to terminate execution" )
50
+ ErrStepFailed = errors .New ("executor step failed" )
51
+ )
52
+
48
53
func NewExecutor (
49
54
taskId int64 ,
50
55
clientToken ,
@@ -133,7 +138,11 @@ func (executor *Executor) RunBuild() {
133
138
}
134
139
135
140
log .Printf ("Executing %s..." , command .Name )
136
- if ! executor .performStep (environment , command ) {
141
+ if err := executor .performStep (environment , command ); err != nil {
142
+ if errors .Is (err , ErrStepExit ) {
143
+ return
144
+ }
145
+
137
146
failedAtLeastOnce = true
138
147
}
139
148
log .Printf ("%s finished!" , command .Name )
@@ -204,14 +213,14 @@ func getExpandedScriptEnvironment(executor *Executor, responseEnvironment map[st
204
213
return result
205
214
}
206
215
207
- func (executor * Executor ) performStep (env map [string ]string , currentStep * api.Command ) bool {
216
+ func (executor * Executor ) performStep (env map [string ]string , currentStep * api.Command ) error {
208
217
success := false
209
218
signaledToExit := false
210
219
start := time .Now ()
211
220
212
221
switch instruction := currentStep .Instruction .(type ) {
213
222
case * api.Command_ExitInstruction :
214
- os . Exit ( 0 )
223
+ return ErrStepExit
215
224
case * api.Command_CloneInstruction :
216
225
success = executor .CloneRepository (env )
217
226
case * api.Command_FileInstruction :
@@ -269,7 +278,12 @@ func (executor *Executor) performStep(env map[string]string, currentStep *api.Co
269
278
time .Sleep (10 * time .Second )
270
279
_ , err = client .CirrusClient .ReportSingleCommand (context .Background (), & reportRequest )
271
280
}
272
- return success
281
+
282
+ if ! success {
283
+ return ErrStepFailed
284
+ }
285
+
286
+ return nil
273
287
}
274
288
275
289
func (executor * Executor ) ExecuteScriptsStreamLogsAndWait (
0 commit comments