Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,8 @@ fi

if [[ "${BUILDKITE_PLUGIN_DOCKER_ALWAYS_PULL:-false}" =~ ^(true|on|1)$ ]] ; then
echo "--- :docker: Pulling ${image}"
if ! retry "${BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES:-3}" \
docker pull "${image}" ; then
retry_exit_status="$?"
retry "${BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES:-3}" docker pull "${image}" || retry_exit_status="$?"
if [ "${retry_exit_status:-0}" -ne 0 ] ; then
echo "!!! :docker: Pull failed."
exit "$retry_exit_status"
fi
Expand Down
2 changes: 1 addition & 1 deletion lib/shared.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function retry {
local attempts=1

until "$@"; do
retry_exit_status=$?
local retry_exit_status=$?
echo "Exited with $retry_exit_status"
if (( retries == "0" )); then
return $retry_exit_status
Expand Down
36 changes: 36 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,42 @@ setup() {
unstub docker
}

@test "Pull image first before running BUILDKITE_COMMAND, success on retries" {
export BUILDKITE_PLUGIN_DOCKER_ALWAYS_PULL=true
export BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES=2

stub docker \
"pull image:tag" \
"pull image:tag : echo pulled latest image on retry" \
"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"

run "$PWD"/hooks/command

assert_success
assert_output --partial "Retrying 1 more times..."
assert_output --partial "pulled latest image on retry"
assert_output --partial "ran command in docker"

unstub docker
}

@test "Pull image first before running BUILDKITE_COMMAND, failure on retries" {
export BUILDKITE_PLUGIN_DOCKER_ALWAYS_PULL=true
export BUILDKITE_PLUGIN_DOCKER_PULL_RETRIES=2

stub docker \
"pull image:tag" \
"pull image:tag : exit 3"

run "$PWD"/hooks/command

assert_failure 3
assert_output --partial "Retrying 1 more times..."
assert_output --partial "!!! :docker: Pull failed."

unstub docker
}

@test "Runs BUILDKITE_COMMAND with mount-buildkite-agent disabled specifically" {
export BUILDKITE_PLUGIN_DOCKER_MOUNT_BUILDKITE_AGENT=false
export BUILDKITE_COMMAND="pwd"
Expand Down