Skip to content

Commit cbfde73

Browse files
authored
Merge pull request #182 from buildkite-plugins/toote_failed_download
Failed download exit code customization
2 parents 8c6477f + 28b1292 commit cbfde73

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ steps:
1414
- wait: ~
1515
continue_on_failure: true
1616
- plugins:
17-
- junit-annotate#v2.2.0:
17+
- junit-annotate#v2.4.0:
1818
artifacts: tmp/junit-*.xml
1919
```
2020
@@ -60,6 +60,12 @@ Default: `false`
6060

6161
If this setting is true and any errors are found in the JUnit XML files during parsing, the annotation step will exit with a non-zero value, which should cause the build to fail.
6262

63+
### `failed-download-exit-code` (optional, integer)
64+
65+
Default: `2`
66+
67+
Exit code of the plugin if the call to `buildkite-agent artifact download` fails.
68+
6369
### `min-tests` (optional, integer)
6470

6571
Minimum amount of run tests that need to be analyzed or a failure will be reported. It is useful to ensure that tests are actually run and report files to analyze do contain information.

hooks/command

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trap cleanup EXIT
3535
echo "--- :junit: Download the junits"
3636
if ! buildkite-agent artifact download "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS}" "$artifacts_dir"; then
3737
echo "--- :boom: Could not download artifacts"
38-
exit 2
38+
exit "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILED_DOWNLOAD_EXIT_CODE:-2}"
3939
fi
4040

4141
echo "--- :junit: Processing the junits"

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ configuration:
1818
- file
1919
fail-build-on-error:
2020
type: boolean
21+
failed-download-exit-code:
22+
type: integer
2123
job-uuid-file-pattern:
2224
type: string
2325
min-tests:

tests/command.bats

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,27 @@ export annotation_input="tests/tmp/annotation.input"
346346
unstub buildkite-agent
347347
}
348348

349+
@test "customize error when agent download fails" {
350+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
351+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILED_DOWNLOAD_EXIT_CODE=5
352+
353+
stub mktemp \
354+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
355+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
356+
357+
stub buildkite-agent \
358+
"artifact download \* \* : exit 1"
359+
360+
run "$PWD/hooks/command"
361+
362+
assert_failure 5
363+
364+
assert_output --partial "Could not download artifacts"
365+
366+
unstub mktemp
367+
unstub buildkite-agent
368+
}
369+
349370
@test "creates annotation with no failures but min tests triggers" {
350371
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
351372
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=1

0 commit comments

Comments
 (0)