Skip to content
Snippets Groups Projects

fix: read error from upload artifacts execution.

Merged Paul 🐻 requested to merge paulrbr/gitlab-runner:fix-artifact-upload-errors into master
All threads resolved!
1 file
+ 29
7
Compare changes
  • Side-by-side
  • Inline
+ 29
7
@@ -9,6 +9,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"
"github.com/Sirupsen/logrus"
@@ -175,24 +176,45 @@ func (b *Build) executeStage(ctx context.Context, buildStage BuildStage, executo
func (b *Build) executeUploadArtifacts(ctx context.Context, state error, executor Executor) (err error) {
jobState := state
for _, artifacts := range b.Artifacts {
when := artifacts.When
err = b.executeUploadArtifactsParallel(ctx, state, executor)
// Use job's error if set
if jobState != nil {
err = jobState
}
return
}
func (b *Build) executeUploadArtifactsParallel(ctx context.Context, state error, executor Executor) (err error) {
var wait sync.WaitGroup
var uploadErrors []error
for _, artifact := range b.Artifacts {
when := artifact.When
if state == nil {
// Previous stages were successful
if when == "" || when == ArtifactWhenOnSuccess || when == ArtifactWhenAlways {
state = b.executeStage(ctx, BuildStageUploadArtifacts, executor)
wait.Add(1)
go func() {
uploadErrors = append(uploadErrors, b.executeStage(ctx, BuildStageUploadArtifacts, executor))
wait.Done()
}()
}
} else {
// Previous stage did fail
if when == ArtifactWhenOnFailure || when == ArtifactWhenAlways {
err = b.executeStage(ctx, BuildStageUploadArtifacts, executor)
wait.Add(1)
go func() {
uploadErrors = append(uploadErrors, b.executeStage(ctx, BuildStageUploadArtifacts, executor))
wait.Done()
}()
}
}
}
wait.Wait()
// Use job's error if set
if jobState != nil {
err = jobState
if uploadErrors != nil {
err = uploadErrors[0]
}
return
}
Loading