Skip to content

Commit 5163d0c

Browse files
committed
Allow for custom annotation contexts
Enables multiple runs of the plugin in a pipeline
1 parent 90f308c commit 5163d0c

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ If this setting is true and any errors are found in the JUnit XML files during
5151
parsing, the annotation step will exit with a non-zero value, which should cause
5252
the build to fail.
5353

54+
### `context` (optional)
55+
Default: `junit`
56+
57+
The buildkite annotation context to use. Useful to differentiate multiple runs of this plugin in a single pipeline.
58+
5459
## Developing
5560

5661
To test the plugin hooks (in Bash) and the junit parser (in Ruby):

hooks/command

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if grep -q "<details>" "$annotation_path"; then
5353

5454
echo "--- :buildkite: Creating annotation"
5555
# shellcheck disable=SC2002
56-
cat "$annotation_path" | buildkite-agent annotate --context junit --style error
56+
cat "$annotation_path" | buildkite-agent annotate --context ${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit} --style error
5757

5858
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]
5959
then

plugin.yml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ configuration:
1616
- file
1717
fail-build-on-error:
1818
type: boolean
19+
context:
20+
type: string
1921
required:
2022
- artifacts
2123
additionalProperties: false

tests/command.bats

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ load "$BATS_PATH/load.bash"
6565
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN="custom_(*)_pattern.xml"
6666
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT="file"
6767
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
68+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT="junit_custom_context"
6869

6970
artifacts_tmp="tests/tmp/$PWD/junit-artifacts"
7071
annotation_tmp="tests/tmp/$PWD/junit-annotation"
@@ -74,7 +75,7 @@ load "$BATS_PATH/load.bash"
7475
"-d junit-annotate-plugin-annotation-tmp.XXXXXXXXXX : mkdir -p $annotation_tmp; echo $annotation_tmp"
7576

7677
stub buildkite-agent "artifact download junits/*.xml /plugin/tests/tmp//plugin/junit-artifacts : echo Downloaded artifacts" \
77-
"annotate --context junit --style error : echo Annotation added"
78+
"annotate --context junit_custom_context --style error : echo Annotation added"
7879

7980
stub docker "--log-level error run --rm --volume /plugin/tests/tmp//plugin/junit-artifacts:/junits --volume /plugin/hooks/../ruby:/src --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN='custom_(*)_pattern.xml' --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT='file' ruby:2.5-alpine /src/bin/annotate /junits : echo '<details>Failure</details>'"
8081

0 commit comments

Comments
 (0)