From c8287ae9b802757b637d9384878d41f2f3aa2548 Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Tue, 15 Oct 2024 16:48:42 -0400 Subject: [PATCH] abort post-command on non-zero exit status resolves #80 if the command (eg, bundle install) fails partway through, the cache plugin could upload a poisoned cache --- hooks/post-command | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hooks/post-command b/hooks/post-command index 11a23cd..c8eec9c 100755 --- a/hooks/post-command +++ b/hooks/post-command @@ -1,6 +1,12 @@ #!/bin/bash set -euo pipefail +# skip caching if command exited non-zero +if [ $BUILDKITE_COMMAND_EXIT_STATUS -ne 0 ] ; then + echo "Aborting cache post-command hook because command exited with status $BUILDKITE_COMMAND_EXIT_STATUS" + exit 1 +fi + DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" # shellcheck source=lib/shared.bash