Skip to content

feat: Add possibility to run plugin without downloading artifacts #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ Default: `true`

Controls whether the JUnit processing should run inside a Docker container. When set to `false`, the processing will run directly on the host using the system's Ruby installation.

### `download-artifacts` (optional, boolean)

Default: `true`

Controls whether the Junit processing should download the artifacts from buildkite or not. When set to `false`, the plugin expects the artifacts to be present without having to download them. Useful to run the plugin in the same step as the one generating the test results.

## Developing

To run testing, shellchecks and plugin linting use use `bk run` with the [Buildkite CLI](https://github.com/buildkite/cli).
Expand Down
13 changes: 9 additions & 4 deletions hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ function check_size {

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 "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILED_DOWNLOAD_EXIT_CODE:-2}"
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_DOWNLOAD_ARTIFACTS:-true}" == "true" ]]; then
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 "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILED_DOWNLOAD_EXIT_CODE:-2}"
fi
else
echo "--- :junit: Using the provided artifacts"
cp -r "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS}" "$artifacts_dir"
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 @@ -32,6 +32,8 @@ configuration:
type: string
run-in-docker:
type: boolean
download-artifacts:
type: boolean
required:
- artifacts
additionalProperties: false
10 changes: 10 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,14 @@ DOCKER_STUB_DEFAULT_OPTIONS='--log-level error run --rm --volume \* --volume \*
unstub buildkite-agent
unstub ruby
rm "${annotation_input}"
}

@test "does not download artifacts when download-artifacts is false" {
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_DOWNLOAD_ARTIFACTS=false

run "$PWD/hooks/command"

assert_output --partial "Using the provided artifacts"
}