Skip to content

Commit 932de25

Browse files
committed
Better handling of errors in docker run
1 parent afecb07 commit 932de25

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

hooks/command

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@ docker \
5050
ruby:2.7-alpine ruby /src/bin/annotate /junits \
5151
> "$annotation_path"
5252

53-
if [[ $? -eq 64 ]]; then # special exit code to signal test failures
53+
exit_code=$?
54+
set -e
55+
56+
if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures
5457
annotation_style="error"
5558
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]; then
5659
fail_build=1
5760
fi
61+
elif [[ $exit_code -ne 0 ]]; then
62+
echo "🚨 Error when processing JUnit tests"
63+
exit $exit_code
5864
fi
5965

60-
set -e
61-
6266
cat "$annotation_path"
6367

6468
if grep -q "<details>" "$annotation_path"; then

tests/command.bats

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ export annotation_input="tests/tmp/annotation.input"
176176
assert_output --partial "Failures too large to annotate"
177177

178178
unstub docker
179-
unstub buildkite-agent
180179
unstub du
180+
unstub buildkite-agent
181181
unstub mktemp
182182
}
183183

@@ -231,6 +231,32 @@ export annotation_input="tests/tmp/annotation.input"
231231

232232
assert_output --partial "Failures too large to annotate"
233233

234+
unstub mktemp
235+
unstub du
236+
unstub buildkite-agent
237+
unstub docker
238+
}
239+
240+
@test "error bubbles up when ruby code fails with anything but 64" {
241+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
242+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
243+
244+
stub mktemp \
245+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
246+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
247+
248+
stub buildkite-agent \
249+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
250+
251+
stub docker \
252+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 147"
253+
254+
run "$PWD/hooks/command"
255+
256+
assert_failure 147
257+
258+
assert_output --partial "Error when processing JUnit tests"
259+
234260
unstub mktemp
235261
unstub buildkite-agent
236262
unstub docker

0 commit comments

Comments
 (0)