diff options
author | Matt Hart <matthew.hart@linaro.org> | 2018-10-19 13:17:59 +0100 |
---|---|---|
committer | Guillaume Tucker <guillaume.tucker@collabora.com> | 2018-11-22 18:06:10 +0000 |
commit | a75f52efef4d18d76759dd694cbddb932a3dd241 (patch) | |
tree | 762d0993c024ae70256e93b4fbdf2732895f573c /src | |
parent | c1d26d333d059e321c85f25a24a397320387feb2 (diff) |
Add retry logic to the docker pull
Sometimes the docker pull command will timeout, presumably due to
dockerhub being unreachable. Catch this error, and retry the pull with
an increasing timeout.
Diffstat (limited to 'src')
-rw-r--r-- | src/org/kernelci/util/Job.groovy | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/org/kernelci/util/Job.groovy b/src/org/kernelci/util/Job.groovy index 0c9ab9b..0fe07d8 100644 --- a/src/org/kernelci/util/Job.groovy +++ b/src/org/kernelci/util/Job.groovy @@ -33,3 +33,22 @@ def addBoolParams(params, bool_params) { [$class: "BooleanParameterValue", name: p.key, value: p.value]) } } + +def dockerPullWithRetry(image, retries=10, sleep_time=1) { + def pulled = false + while (!pulled) { + try { + docker.image(image).pull() + pulled = true + } + catch (Exception e) { + if (!retries) { + throw e + } + echo("""Docker pull failed, retry count ${retries}: ${e.toString()}""") + sleep sleep_time + retries -= 1 + sleep_time = sleep_time * 2 + } + } +} |