Skip to content

Commit d171d63

Browse files
committed
fix: error handling for build image stage
1 parent 16267b7 commit d171d63

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

ci-runner/helper/DockerHelper.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,27 +366,30 @@ func (impl *DockerHelperImpl) executeDockerReBuild(ciContext cicxt.CiContext, k8
366366
func (impl *DockerHelperImpl) buildImageStage(ciContext cicxt.CiContext, dockerBuild string,
367367
useBuildxK8sDriver bool, k8sClient BuildxK8sInterface, buildLogs []any) func() error {
368368
return func() error {
369-
if len(buildLogs) > 0 {
370-
log.Println(buildLogs...)
371-
}
372-
ctx, cancel := context.WithCancelCause(ciContext)
373-
defer cancel(nil)
369+
ctx, cancel := context.WithCancel(ciContext)
370+
defer cancel()
374371
errGroup, groupCtx := errgroup.WithContext(ctx)
375372
errGroup.Go(func() error {
376373
if useBuildxK8sDriver && k8sClient != nil {
377-
return k8sClient.CatchBuilderPodLivenessError(groupCtx)
374+
if err := k8sClient.CatchBuilderPodLivenessError(groupCtx); err != nil {
375+
cancel() // Cancel the context if there's an error in catching builder pod liveness
376+
return err
377+
}
378378
}
379379
return nil
380380
})
381381
errGroup.Go(func() error {
382+
if len(buildLogs) > 0 {
383+
log.Println(buildLogs...)
384+
}
382385
err := impl.runDockerBuildCommand(cicxt.BuildCiContext(groupCtx, ciContext.EnableSecretMasking), dockerBuild)
383386
if err != nil {
384387
return err
385388
}
389+
cancel() // Cancel the context after the build is done
386390
return nil
387391
})
388392
if err := errGroup.Wait(); err != nil {
389-
cancel(err)
390393
return err
391394
}
392395
return nil

0 commit comments

Comments
 (0)