@@ -15,6 +15,8 @@ annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXX
15
15
annotation_path=" ${annotation_dir} /annotation.md"
16
16
annotation_style=" info"
17
17
fail_build=0
18
+ has_errors=0
19
+ create_annotation=0
18
20
19
21
function cleanup {
20
22
rm -rf " ${artifacts_dir} "
@@ -54,8 +56,11 @@ exit_code=$?
54
56
set -e
55
57
56
58
if [[ $exit_code -eq 64 ]]; then # special exit code to signal test failures
59
+ has_errors=1
60
+ create_annotation=1
57
61
annotation_style=" error"
58
62
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"
59
64
fail_build=1
60
65
fi
61
66
elif [[ $exit_code -ne 0 ]]; then
65
70
66
71
cat " $annotation_path "
67
72
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
77
77
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
78
82
fi
79
83
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 "
85
88
fi
89
+
90
+ exit $fail_build
0 commit comments