Skip to content

Commit b8e06dd

Browse files
committed
Added always_annotate option
1 parent f473aa6 commit b8e06dd

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ The artifact glob path to find the JUnit XML files.
2626

2727
Example: `tmp/junit-*.xml`
2828

29+
### `allways-annotate` (optional, boolean)
30+
31+
Forces the creation of the annotation even when no failures or errors are found
32+
2933
### `job-uuid-file-pattern` (optional)
3034
Default: `-(.*).xml`
3135

hooks/command

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXX
1515
annotation_path="${annotation_dir}/annotation.md"
1616
annotation_style="info"
1717
fail_build=0
18+
has_errors=0
19+
create_annotation=0
1820

1921
function cleanup {
2022
rm -rf "${artifacts_dir}"
@@ -54,8 +56,11 @@ exit_code=$?
5456
set -e
5557

5658
if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures
59+
has_errors=1
60+
create_annotation=1
5761
annotation_style="error"
5862
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]; then
63+
echo "--- :boom: Build will fail due to errors being found"
5964
fail_build=1
6065
fi
6166
elif [[ $exit_code -ne 0 ]]; then
@@ -65,21 +70,21 @@ fi
6570

6671
cat "$annotation_path"
6772

68-
if grep -q "<details>" "$annotation_path"; then
69-
if ! check_size; then
70-
echo "--- :warning: Failures too large to annotate"
71-
msg="The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
72-
echo "$msg"
73-
else
74-
echo "--- :buildkite: Creating annotation"
75-
# shellcheck disable=SC2002
76-
cat "$annotation_path" | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style "$annotation_style"
73+
if [ $has_errors -eq 0 ]; then
74+
# done in nested if to simplify outer conditions
75+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ALWAYS_ANNOTATE:-false}" =~ (true|on|1) ]]; then
76+
create_annotation=1
7777
fi
78+
elif ! check_size; then
79+
echo "--- :warning: Failures too large to annotate"
80+
echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
81+
create_annotation=0
7882
fi
7983

80-
if ((fail_build)); then
81-
echo "--- :boom: Failing build due to error"
82-
exit 1
83-
else
84-
exit 0
84+
if [ $create_annotation -ne 0 ]; then
85+
echo "--- :buildkite: Creating annotation"
86+
# shellcheck disable=SC2002
87+
cat "$annotation_path" | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style "$annotation_style"
8588
fi
89+
90+
exit $fail_build

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ configuration:
77
properties:
88
artifacts:
99
type: string
10+
allways-annotate:
11+
type: boolean
1012
context:
1113
type: string
1214
failure-format:

0 commit comments

Comments
 (0)