Skip to content

Commit a540f5d

Browse files
authored
Merge pull request #84 from amancevice/abort-post-command
abort post-command on non-zero exit status
2 parents b2e2172 + 5b65ca6 commit a540f5d

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

hooks/post-command

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/bin/bash
22
set -euo pipefail
33

4+
# skip caching if command exited non-zero
5+
if [ "${BUILDKITE_COMMAND_EXIT_STATUS}" -ne 0 ] ; then
6+
echo "Aborting cache post-command hook because command exited with status $BUILDKITE_COMMAND_EXIT_STATUS"
7+
exit 0
8+
fi
9+
410
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
511

612
# shellcheck source=lib/shared.bash

tests/post-command-tgz.bats

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
setup() {
88
load "${BATS_PLUGIN_PATH}/load.bash"
99

10+
export BUILDKITE_COMMAND_EXIT_STATUS=0
11+
1012
mkdir -p tests/data/my_files
1113
echo "all the llamas" > "tests/data/my_files/llamas.txt"
1214
echo "no alpacas" > "tests/data/my_files/alpacas.txt"

tests/post-command-zip.bats

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
setup() {
88
load "${BATS_PLUGIN_PATH}/load.bash"
99

10+
export BUILDKITE_COMMAND_EXIT_STATUS=0
11+
1012
mkdir -p tests/data/my_files
1113
echo "all the llamas" > "tests/data/my_files/llamas.txt"
1214
echo "no alpacas" > "tests/data/my_files/alpacas.txt"

tests/post-command.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
setup() {
77
load "${BATS_PLUGIN_PATH}/load.bash"
88

9+
export BUILDKITE_COMMAND_EXIT_STATUS=0
10+
911
mkdir -p tests/data/my_files
1012
echo "all the llamas" > "tests/data/my_files/llamas.txt"
1113
echo "no alpacas" > "tests/data/my_files/alpacas.txt"
@@ -34,6 +36,15 @@ teardown() {
3436
assert_output --partial 'Cache not setup for saving'
3537
}
3638

39+
@test 'If command failed, do nothing' {
40+
export BUILDKITE_COMMAND_EXIT_STATUS=127
41+
42+
run "$PWD/hooks/post-command"
43+
44+
assert_success
45+
assert_output --partial 'Aborting cache post-command hook because command exited with status 127'
46+
}
47+
3748
@test "Missing path fails" {
3849
unset BUILDKITE_PLUGIN_CACHE_PATH
3950

0 commit comments

Comments
 (0)