Skip to content

Commit 41a0163

Browse files
ntsemahdpressle
authored andcommitted
Add 3 attempts to push docker image
Docker push fail due to Harbor issues. Add 3-attempt retry loop and a 10-second delay between attempts. Signed-off-by: Noam Tsemah <ntsemah@nvidia.com>
1 parent 66a171f commit 41a0163

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/com/mellanox/cicd/Matrix.groovy

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,22 @@ def buildImage(img, filename, extra_args, config, image) {
11931193
if (preBuild) {
11941194
run_shell(preBuild, "Image preparation script")
11951195
}
1196-
customImage = docker.build("${img}", "-f ${filename} ${extra_args} . ")
1197-
customImage.push()
1196+
1197+
def customImage = docker.build("${img}", "-f ${filename} ${extra_args} . ")
1198+
def maxAttempts = 3
1199+
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
1200+
try {
1201+
customImage.push()
1202+
break
1203+
} catch (Exception e) {
1204+
if (attempt < maxAttempts) {
1205+
config.logger.warn("Docker push attempt ${attempt}/${maxAttempts} failed for ${img}: ${e.message}. Retrying...")
1206+
sleep(time: 10, unit: 'SECONDS')
1207+
} else {
1208+
reportFail('docker push', "Failed to push '${img}' after ${maxAttempts} attempts. Last error: ${e.message}")
1209+
}
1210+
}
1211+
}
11981212
}
11991213

12001214
Boolean isEnvVarSet(var) {

0 commit comments

Comments
 (0)