Skip to content
Snippets Groups Projects
Commit 9eec92c8 authored by Paul B's avatar Paul B
Browse files

fix: read error from upload artifacts execution. Fixes #2584.

parent 7514fd2e
No related branches found
No related tags found
No related merge requests found
......@@ -173,27 +173,17 @@ 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
if state == nil {
// Previous stages were successful
if when == "" || when == ArtifactWhenOnSuccess || when == ArtifactWhenAlways {
state = b.executeStage(ctx, BuildStageUploadArtifacts, executor)
}
} else {
// Previous stage did fail
if when == ArtifactWhenOnFailure || when == ArtifactWhenAlways {
err = b.executeStage(ctx, BuildStageUploadArtifacts, executor)
}
var uploadError error
for _, artifact := range b.JobResponse.Artifacts {
if artifact.ShouldUpload(state) {
uploadError = b.executeStage(ctx, BuildStageUploadArtifacts, executor)
}
if uploadError != nil {
err = uploadError
}
}
// Use job's error if set
if jobState != nil {
err = jobState
}
return
}
......@@ -226,7 +216,14 @@ func (b *Build) executeScript(ctx context.Context, executor Executor) error {
if err == nil {
err = b.executeStage(ctx, BuildStageArchiveCache, executor)
}
err = b.executeUploadArtifacts(ctx, err, executor)
jobState := err
err = b.executeUploadArtifacts(ctx, jobState, executor)
// Use job's error if set
if jobState != nil {
err = jobState
}
return err
}
......
......@@ -168,6 +168,14 @@ const (
ArtifactWhenAlways ArtifactWhen = "always"
)
func (when ArtifactWhen) OnSuccess() bool {
return when == "" || when == ArtifactWhenOnSuccess || when == ArtifactWhenAlways
}
func (when ArtifactWhen) OnFailure() bool {
return when == ArtifactWhenOnFailure || when == ArtifactWhenAlways
}
type Artifact struct {
Name string `json:"name"`
Untracked bool `json:"untracked"`
......@@ -176,6 +184,10 @@ type Artifact struct {
ExpireIn string `json:"expire_in"`
}
func (a Artifact) ShouldUpload(state error) bool {
return (state == nil && a.When.OnSuccess()) || (state != nil && a.When.OnFailure())
}
type Artifacts []Artifact
type Cache struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment