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

DESS-1710: modified WaitForBuildToFinish function #4270

Merged
Merged
30 changes: 28 additions & 2 deletions pkg/jenkins/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,38 @@ type Build interface {
}

// WaitForBuildToFinish waits till a build is finished.
func WaitForBuildToFinish(ctx context.Context, build Build, pollInterval time.Duration) {
func WaitForBuildToFinish(ctx context.Context, build Build, pollInterval time.Duration) error {
//TODO: handle timeout?
maxRetries := 4

for build.IsRunning(ctx) {
time.Sleep(pollInterval)
build.Poll(ctx)
//TODO: add 404/503 response code handling
_, err := build.Poll(ctx)

if err == nil {
continue
}

fmt.Printf("Error occurred while waiting for build to finish: %v. Retrying...\n", err)

for i := 0; i < maxRetries; i++ {
time.Sleep(pollInterval)
_, err = build.Poll(ctx)

if err == nil {
break
}

fmt.Printf("Error occurred while waiting for build to finish: %v. Retrying...\n", err)
}

if err != nil {
return fmt.Errorf("Max retries (%v) exceeded while waiting for build to finish. Last error: %w", maxRetries, err)
}
}

return nil
}

// FetchBuildArtifact is fetching a build artifact from a finished build with a certain name.
Expand Down