@@ -11,6 +11,7 @@ import (
11
11
"regexp"
12
12
"strings"
13
13
"sync"
14
+ "time"
14
15
15
16
"github.com/SAP/jenkins-library/pkg/log"
16
17
"github.com/pkg/errors"
@@ -240,20 +241,24 @@ func downloadJre(config *ScanOptions, utils Utils) (string, error) {
240
241
javaPath := "java"
241
242
if err != nil {
242
243
log .Entry ().Infof ("No Java installation found, downloading JVM from %v" , config .JreDownloadURL )
243
- err = utils .DownloadFile (config .JreDownloadURL , jvmTarGz , nil , nil )
244
- if err != nil {
245
- // we check if the copy error occurs and retry the download
246
- // if the copy error did not happen, we rerun the whole download mechanism once
247
- if strings .Contains (err .Error (), "unable to copy content from url to file" ) {
248
- // retry the download once again
249
- log .Entry ().Warnf ("Previous Download failed due to %v" , err )
250
- err = nil
251
- err = utils .DownloadFile (config .JreDownloadURL , jvmTarGz , nil , nil )
244
+ const maxRetries = 3
245
+ retries := 0
246
+ for retries < maxRetries {
247
+ err = utils .DownloadFile (config .JreDownloadURL , jvmTarGz , nil , nil )
248
+ if err == nil {
249
+ break
250
+ }
251
+ log .Entry ().Warnf ("Attempt %d: Download failed due to %v" , retries + 1 , err )
252
+ retries ++
253
+ if retries >= maxRetries {
254
+ log .Entry ().Errorf ("Download failed after %d attempts" , retries )
255
+ return "" , errors .Wrapf (err , "failed to download jre from URL '%s'" , config .JreDownloadURL )
252
256
}
257
+ time .Sleep (1 * time .Second )
253
258
}
254
259
255
260
if err != nil {
256
- return "" , errors .Wrapf (err , "failed to download jre from URL '%s'" , config .JreDownloadURL )
261
+ return "" , errors .Wrapf (err , "Even after retry failed to download jre from URL '%s'" , config .JreDownloadURL )
257
262
}
258
263
259
264
// ToDo: replace tar call with go library call
0 commit comments