Skip to content

Commit

Permalink
Merge pull request #182 from buildkite-plugins/toote_failed_download
Browse files Browse the repository at this point in the history
Failed download exit code customization
  • Loading branch information
pzeballos authored Nov 3, 2022
2 parents 8c6477f + 28b1292 commit cbfde73
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ steps:
- wait: ~
continue_on_failure: true
- plugins:
- junit-annotate#v2.2.0:
- junit-annotate#v2.4.0:
artifacts: tmp/junit-*.xml
```
Expand Down Expand Up @@ -60,6 +60,12 @@ Default: `false`

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.

### `failed-download-exit-code` (optional, integer)

Default: `2`

Exit code of the plugin if the call to `buildkite-agent artifact download` fails.

### `min-tests` (optional, integer)

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.
Expand Down
2 changes: 1 addition & 1 deletion hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trap cleanup EXIT
echo "--- :junit: Download the junits"
if ! buildkite-agent artifact download "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS}" "$artifacts_dir"; then
echo "--- :boom: Could not download artifacts"
exit 2
exit "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILED_DOWNLOAD_EXIT_CODE:-2}"
fi

echo "--- :junit: Processing the junits"
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ configuration:
- file
fail-build-on-error:
type: boolean
failed-download-exit-code:
type: integer
job-uuid-file-pattern:
type: string
min-tests:
Expand Down
21 changes: 21 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,27 @@ export annotation_input="tests/tmp/annotation.input"
unstub buildkite-agent
}

@test "customize error when agent download fails" {
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILED_DOWNLOAD_EXIT_CODE=5

stub mktemp \
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"

stub buildkite-agent \
"artifact download \* \* : exit 1"

run "$PWD/hooks/command"

assert_failure 5

assert_output --partial "Could not download artifacts"

unstub mktemp
unstub buildkite-agent
}

@test "creates annotation with no failures but min tests triggers" {
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=1
Expand Down

0 comments on commit cbfde73

Please sign in to comment.