From c580bc80556fc0664410acfd61df9d7aa3562bda Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Fri, 6 Jul 2018 18:12:43 +1000 Subject: [PATCH] Make sure to exit 1 on command fails --- README.md | 2 +- hooks/command | 2 +- tests/command.bats | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fb2502a..f2b7840 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Example: `nvidia` ### `shell` (optional) -Set the shell to use for the command. Set it to `false` to pass the command directly to the `docker run` command. The default is `bash -c`. +Set the shell to use for the command. Set it to `false` to pass the command directly to the `docker run` command. The default is `bash -e -c`. Example: `powershell -Command` diff --git a/hooks/command b/hooks/command index 25dd571..b0376be 100755 --- a/hooks/command +++ b/hooks/command @@ -84,7 +84,7 @@ if [[ -n "${BUILDKITE_PLUGIN_DOCKER_ENTRYPOINT:-}" ]] ; then BUILDKITE_PLUGIN_DOCKER_SHELL="${BUILDKITE_PLUGIN_DOCKER_SHELL:-false}" fi -BUILDKITE_PLUGIN_DOCKER_SHELL="${BUILDKITE_PLUGIN_DOCKER_SHELL:-bash -c}" +BUILDKITE_PLUGIN_DOCKER_SHELL="${BUILDKITE_PLUGIN_DOCKER_SHELL:-bash -e -c}" if [[ "${BUILDKITE_PLUGIN_DOCKER_SHELL}" =~ ^(false|off|0)$ ]] ; then BUILDKITE_PLUGIN_DOCKER_SHELL='' diff --git a/tests/command.bats b/tests/command.bats index 6fa4dab..d0fcddb 100644 --- a/tests/command.bats +++ b/tests/command.bats @@ -12,7 +12,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_AGENT_BINARY_PATH="/buildkite-agent" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app --env BUILDKITE_JOB_ID --env BUILDKITE_BUILD_ID --env BUILDKITE_AGENT_ACCESS_TOKEN --volume /buildkite-agent:/usr/bin/buildkite-agent image:tag bash -c 'command1 \"a string\"' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app --env BUILDKITE_JOB_ID --env BUILDKITE_BUILD_ID --env BUILDKITE_AGENT_ACCESS_TOKEN --volume /buildkite-agent:/usr/bin/buildkite-agent image:tag bash -e -c 'command1 \"a string\"' : echo ran command in docker" run $PWD/hooks/command @@ -31,7 +31,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_AGENT_BINARY_PATH="/buildkite-agent" stub docker \ - "run -it --rm --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 image:tag bash -c 'command1 \"a string\"' : echo ran command in docker" + "run -it --rm --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 image:tag bash -e -c 'command1 \"a string\"' : echo ran command in docker" run $PWD/hooks/command @@ -53,7 +53,7 @@ load '/usr/local/lib/bats/load.bash' stub docker \ "pull image:tag : echo pulled latest image" \ - "run -it --rm --volume $PWD:/app --workdir /app image:tag bash -c 'pwd' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app image:tag bash -e -c 'pwd' : echo ran command in docker" run $PWD/hooks/command @@ -77,7 +77,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_COMMAND="pwd" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app image:tag bash -c 'pwd' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app image:tag bash -e -c 'pwd' : echo ran command in docker" run $PWD/hooks/command @@ -100,7 +100,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_COMMAND="echo hello world; pwd" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app --volume /hello:/hello-world --volume /var/run/docker.sock:/var/run/docker.sock image:tag bash -c 'echo hello world; pwd' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app --volume /hello:/hello-world --volume /var/run/docker.sock:/var/run/docker.sock image:tag bash -e -c 'echo hello world; pwd' : echo ran command in docker" run $PWD/hooks/command @@ -125,7 +125,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_COMMAND="echo hello world" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app --env MY_TAG=value --env ANOTHER_TAG=llamas image:tag bash -c 'echo hello world' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app --env MY_TAG=value --env ANOTHER_TAG=llamas image:tag bash -e -c 'echo hello world' : echo ran command in docker" run $PWD/hooks/command @@ -148,7 +148,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_COMMAND="echo hello world" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app -u foo image:tag bash -c 'echo hello world' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app -u foo image:tag bash -e -c 'echo hello world' : echo ran command in docker" run $PWD/hooks/command @@ -171,7 +171,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_COMMAND="echo hello world" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app --group-add foo --group-add bar image:tag bash -c 'echo hello world' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app --group-add foo --group-add bar image:tag bash -e -c 'echo hello world' : echo ran command in docker" run $PWD/hooks/command @@ -196,7 +196,7 @@ load '/usr/local/lib/bats/load.bash' stub docker \ "network ls --quiet --filter 'name=foo' : echo " \ "network create foo : echo creating network foo" \ - "run -it --rm --volume $PWD:/app --workdir /app --network foo image:tag bash -c 'echo hello world' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app --network foo image:tag bash -e -c 'echo hello world' : echo ran command in docker" run $PWD/hooks/command @@ -220,7 +220,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_COMMAND="echo hello world" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app image:tag bash -c 'echo hello world' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app image:tag bash -e -c 'echo hello world' : echo ran command in docker" run $PWD/hooks/command @@ -244,7 +244,7 @@ load '/usr/local/lib/bats/load.bash' export BUILDKITE_COMMAND="echo hello world" stub docker \ - "run -it --rm --volume $PWD:/app --workdir /app --runtime custom_runtime image:tag bash -c 'echo hello world' : echo ran command in docker" + "run -it --rm --volume $PWD:/app --workdir /app --runtime custom_runtime image:tag bash -e -c 'echo hello world' : echo ran command in docker" run $PWD/hooks/command