File tree Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 348348
349349if [[ " ${BUILDKITE_PLUGIN_DOCKER_ALWAYS_PULL:- false} " =~ ^(true| on| 1)$ ]] ; then
350350 echo " --- :docker: Pulling ${image} "
351- if ! retry " ${BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES:- 3} " \
352- docker pull " ${image} " ; then
353- retry_exit_status=" $? "
351+ retry " ${BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES:- 3} " docker pull " ${image} " || retry_exit_status=" $? "
352+ if [ " ${retry_exit_status:- 0} " -ne 0 ] ; then
354353 echo " !!! :docker: Pull failed."
355354 exit " $retry_exit_status "
356355 fi
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ function retry {
88 local attempts=1
99
1010 until " $@ " ; do
11- retry_exit_status=$?
11+ local retry_exit_status=$?
1212 echo " Exited with $retry_exit_status "
1313 if (( retries == "0 " )) ; then
1414 return $retry_exit_status
Original file line number Diff line number Diff line change @@ -66,6 +66,42 @@ setup() {
6666 unstub docker
6767}
6868
69+ @test " Pull image first before running BUILDKITE_COMMAND, success on retries" {
70+ export BUILDKITE_PLUGIN_DOCKER_ALWAYS_PULL=true
71+ export BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES=2
72+
73+ stub docker \
74+ " pull image:tag" \
75+ " pull image:tag : echo pulled latest image on retry" \
76+ " run -t -i --rm --init --volume $PWD :/workdir --workdir /workdir --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'pwd' : echo ran command in docker"
77+
78+ run " $PWD " /hooks/command
79+
80+ assert_success
81+ assert_output --partial " Retrying 1 more times..."
82+ assert_output --partial " pulled latest image on retry"
83+ assert_output --partial " ran command in docker"
84+
85+ unstub docker
86+ }
87+
88+ @test " Pull image first before running BUILDKITE_COMMAND, failure on retries" {
89+ export BUILDKITE_PLUGIN_DOCKER_ALWAYS_PULL=true
90+ export BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES=2
91+
92+ stub docker \
93+ " pull image:tag" \
94+ " pull image:tag : exit 3"
95+
96+ run " $PWD " /hooks/command
97+
98+ assert_failure 3
99+ assert_output --partial " Retrying 1 more times..."
100+ assert_output --partial " !!! :docker: Pull failed."
101+
102+ unstub docker
103+ }
104+
69105@test " Runs BUILDKITE_COMMAND with mount-buildkite-agent disabled specifically" {
70106 export BUILDKITE_PLUGIN_DOCKER_MOUNT_BUILDKITE_AGENT=false
71107 export BUILDKITE_COMMAND=" pwd"
You can’t perform that action at this time.
0 commit comments