Skip to content

Commit e914d65

Browse files
committed
Graceful handling of artifact errors
1 parent 932de25 commit e914d65

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

hooks/command

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ fi
1010
PLUGIN_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)/.."
1111
MAX_SIZE=1024 # in KB
1212

13-
echo "--- :junit: Download the junits"
14-
1513
artifacts_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX")"
1614
annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXXXXX")"
1715
annotation_path="${annotation_dir}/annotation.md"
@@ -31,9 +29,11 @@ function check_size {
3129

3230
trap cleanup EXIT
3331

34-
buildkite-agent artifact download \
35-
"${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS}" \
36-
"$artifacts_dir"
32+
echo "--- :junit: Download the junits"
33+
if ! buildkite-agent artifact download "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS}" "$artifacts_dir"; then
34+
echo "--- :boom: Could not download artifacts"
35+
exit 2
36+
fi
3737

3838
echo "--- :junit: Processing the junits"
3939

@@ -59,7 +59,7 @@ if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures
5959
fail_build=1
6060
fi
6161
elif [[ $exit_code -ne 0 ]]; then
62-
echo "🚨 Error when processing JUnit tests"
62+
echo "--- :boom: Error when processing JUnit tests"
6363
exit $exit_code
6464
fi
6565

tests/command.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,27 @@ export annotation_input="tests/tmp/annotation.input"
260260
unstub mktemp
261261
unstub buildkite-agent
262262
unstub docker
263+
}
264+
265+
266+
267+
@test "error bubbles up when agent download fails" {
268+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
269+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
270+
271+
stub mktemp \
272+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
273+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
274+
275+
stub buildkite-agent \
276+
"artifact download \* \* : exit 1"
277+
278+
run "$PWD/hooks/command"
279+
280+
assert_failure 2
281+
282+
assert_output --partial "Could not download artifacts"
283+
284+
unstub mktemp
285+
unstub buildkite-agent
263286
}

0 commit comments

Comments
 (0)