Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser Davidson committed Oct 23, 2023
1 parent 8211061 commit 20b54ed
Showing 1 changed file with 23 additions and 4 deletions.
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
}

0 comments on commit 20b54ed

Please sign in to comment.