Skip to content

Commit a8977b3

Browse files
committed
Add 3 attempts to build+push docker image
Build and push docker images fails due to harbor issues. Wrap docker.build and customImage.push in buildImage() with a 3-attempt retry loop and a 5-second delay between attempts. Signed-off-by: Noam Tsemah <ntsemah@nvidia.com>
1 parent dd4da82 commit a8977b3

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
@@ -1185,8 +1185,22 @@ def buildImage(img, filename, extra_args, config, image) {
11851185
if (preBuild) {
11861186
run_shell(preBuild, "Image preparation script")
11871187
}
1188-
customImage = docker.build("${img}", "-f ${filename} ${extra_args} . ")
1189-
customImage.push()
1188+
1189+
def maxAttempts = 3
1190+
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
1191+
try {
1192+
customImage = docker.build("${img}", "-f ${filename} ${extra_args} . ")
1193+
customImage.push()
1194+
break
1195+
} catch (Exception e) {
1196+
config.logger.warn("Docker build/push attempt ${attempt}/${maxAttempts} failed for ${img}: ${e.message}")
1197+
if (attempt < maxAttempts) {
1198+
sleep(time: 5, unit: 'SECONDS')
1199+
} else {
1200+
reportFail('docker build', "Docker build/push failed after ${maxAttempts} attempts for ${img}")
1201+
}
1202+
}
1203+
}
11901204
}
11911205

11921206
Boolean isEnvVarSet(var) {

0 commit comments

Comments
 (0)