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
13 changes: 12 additions & 1 deletion commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ if [[ "${BUILDKITE_PLUGIN_DOCKER_INIT:-$init_default}" =~ ^(true|on|1)$ ]] ; the
args+=("--init")
fi

# Explicitly set --stop-timout to match BUILDKITE_CANCEL_GRACE_PERIOD, unless
# BUILDKITE_CANCEL_GRACE_PERIOD is 10, which is the default for both
if [ "${BUILDKITE_CANCEL_GRACE_PERIOD:-10}" != "10" ] ; then
args+=("--stop-timeout" "${BUILDKITE_CANCEL_GRACE_PERIOD:-10}")
fi

# Parse tmpfs property.
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_TMPFS ; then
for arg in "${result[@]}" ; do
Expand Down Expand Up @@ -511,9 +517,14 @@ echo
# would exit the parent shell (here) early.
set +e

# Prevent SIGTERM from killing this script. SIGTERM will still be passed to the Docker container, which can exit
# gracefully (or, if necessary, non-gracefully per the `--stop-timeout` flag passed above).
trap '' SIGTERM

# Don't convert paths on gitbash on windows, as that can mangle user paths and cmd options.
# See https://github.com/buildkite-plugins/docker-buildkite-plugin/issues/81 for more information.
( if is_windows ; then export MSYS_NO_PATHCONV=1; fi && docker run "${args[@]}" )
# `trap` is used in this subshell for the same reason it is used above.
( if is_windows ; then export MSYS_NO_PATHCONV=1; fi && trap '' SIGTERM && docker run "${args[@]}" )

exit_code=$?

Expand Down
17 changes: 17 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,23 @@ EOF
unstub docker
}

@test "Runs with BUILDKITE_COMMAND with non-default grace period" {
export BUILDKITE_COMMAND='command1 "a string"'
export BUILDKITE_AGENT_BINARY_PATH="/buildkite-agent"
export BUILDKITE_CANCEL_GRACE_PERIOD="40"
unset BUILDKITE_PLUGIN_DOCKER_MOUNT_BUILDKITE_AGENT

stub docker \
"run -t -i --rm --init --stop-timeout 40 --volume $PWD:/workdir --workdir /workdir --env BUILDKITE_JOB_ID --env BUILDKITE_BUILD_ID --env BUILDKITE_AGENT_ACCESS_TOKEN --volume /buildkite-agent:/usr/bin/buildkite-agent --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'command1 \"a string\"' : echo ran command in docker"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran command in docker"

unstub docker
}

@test "Use ssh agent (true)" {
skip 'Can not create a socket for testing :('
export BUILDKITE_PLUGIN_DOCKER_MOUNT_SSH_AGENT=true
Expand Down