Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTR-97: Add additional Azure DevOps error handling #4

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions azuredevops/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"

"github.com/avast/retry-go"
Expand Down Expand Up @@ -112,6 +113,19 @@ func (a *AzureDevOps) QueueBuild(projectName string, definitionId *int, sourceBr

response, err := client.Send(a.ctx, http.MethodPost, locationId, "5.1", routeValues, queryParams, bytes.NewReader(body), "application/json", "application/json", nil)
if err != nil {
if _, ok := err.(azuredevops.WrappedError); ok {
wrappedError := err.(azuredevops.WrappedError)
if *wrappedError.TypeKey == "BuildRequestValidationFailedException" {
validationResults := (*wrappedError.CustomProperties)["ValidationResults"]
builder := &strings.Builder{}
for i, v := range validationResults.([]interface{}) {
message := v.(map[string]interface{})["message"]
index := i + 1
builder.WriteString(fmt.Sprintf("\n%d) %s", index, message))
}
return nil, fmt.Errorf("%s %s", err.Error(), builder.String())
}
}
return nil, err
}

Expand All @@ -135,13 +149,18 @@ func (a *AzureDevOps) QueueBuild(projectName string, definitionId *int, sourceBr
}

// WaitForBuild waits for a Build to complete
func (a *AzureDevOps) WaitForBuild(projectName string, buildId *int, attempts uint, interval int) (*build.Build, error) {
var build *build.Build
func (a *AzureDevOps) WaitForBuild(projectName string, buildId *int, attempts uint, interval int) error {
err := retry.Do(
func() error {
var err error
build, err = a.GetBuild(projectName, buildId)
build, err := a.GetBuild(projectName, buildId)
if err != nil {
if _, ok := err.(azuredevops.WrappedError); ok {
wrappedError := err.(azuredevops.WrappedError)
if *wrappedError.TypeKey == "BuildNotFoundException" {
return retry.Unrecoverable(err)
}
}
return err
}

Expand All @@ -160,5 +179,5 @@ func (a *AzureDevOps) WaitForBuild(projectName string, buildId *int, attempts ui
retry.LastErrorOnly(true),
)

return build, err
return err
}