Skip to content

Commit b5323d9

Browse files
authored
Merge pull request #66 from jtszalay/annotation-fix
Add job label to message and amend annotation.
2 parents 21268b2 + 956b720 commit b5323d9

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

hooks/pre-exit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ annotation-link() {
5858
REPORT_COUNT=$((REPORT_COUNT + 1))
5959
done
6060

61-
echo -e "Check the test report(s) here: \n\n${REPORTS}" | buildkite-agent annotate --style info --context "test-collector"
61+
echo -e "Check the ${BUILDKITE_LABEL} test report(s) here: \n\n${REPORTS}" | buildkite-agent annotate --style info --context "test-collector" --append
6262
else
6363
echo "There are no report URLs to annotate."
6464
fi
@@ -162,7 +162,7 @@ find_and_upload() {
162162
else
163163
declare -a uploads_in_progress=()
164164
echo "Uploading '${#matching_files[@]}' files matching '${FILES_PATTERN}'"
165-
165+
166166
# needs to be part of else for bash4.3 compatibility
167167
for file in "${matching_files[@]}"; do
168168
iterations_waited=0
@@ -195,7 +195,7 @@ find_and_upload() {
195195
else
196196
response_file="$(mktemp -t 'response.XXXXXX')"
197197
fi
198-
198+
199199
if ! upload "$TOKEN_VALUE" "$FORMAT" "${file}" "${response_file}"; then
200200
echo "Error uploading, will continue"
201201
fi

tests/pre-exit-report-link.bats

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ setup() {
1818
export BUILDKITE_BRANCH="a-branch"
1919
export BUILDKITE_COMMIT="a-commit"
2020
export BUILDKITE_BUILD_NUMBER="123"
21+
export BUILDKITE_LABEL="A test step"
2122
export BUILDKITE_JOB_ID="321"
2223
export BUILDKITE_MESSAGE="A message"
2324
export BUILDKITE_PLUGIN_TEST_COLLECTOR_ANNOTATION_LINK="true"
@@ -28,8 +29,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
2829

2930
@test "Annotates report link with jq" {
3031
stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success'"
31-
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
32-
32+
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"
33+
3334
run "$PWD/hooks/pre-exit"
3435

3536
assert_success
@@ -44,9 +45,9 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
4445

4546
@test "Annotates report link without jq" {
4647
stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success'"
47-
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
48+
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"
4849
stub which "jq : exit 1"
49-
50+
5051
run "$PWD/hooks/pre-exit"
5152

5253
assert_success
@@ -67,8 +68,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
6768
"-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success 1'" \
6869
"-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success 2'" \
6970
"-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success 3'"
70-
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
71-
71+
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"
72+
7273

7374
run "$PWD/hooks/pre-exit"
7475

@@ -96,8 +97,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
9697
"-r '.run_url' \* : echo https://buildkite.com/organizations/example/analytics/suites/collector-test/runs/1" \
9798
"-r '.run_url' \* : echo https://buildkite.com/organizations/example/analytics/suites/collector-test/runs/2" \
9899
"-r '.run_url' \* : echo https://buildkite.com/organizations/example/analytics/suites/collector-test/runs/1"
99-
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success' with stdin:; cat"
100-
100+
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success' with stdin:; cat"
101+
101102

102103
run "$PWD/hooks/pre-exit"
103104

@@ -119,8 +120,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
119120
@test "Annotates report link absorbs empty file error" {
120121
export CURL_RESP_FILE="response.json"
121122
stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success'"
122-
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
123-
123+
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"
124+
124125
run "$PWD/hooks/pre-exit"
125126

126127
assert_success
@@ -134,7 +135,7 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
134135
@test "No annotation when url property on json response is missing" {
135136
export CURL_RESP_FILE="./tests/fixtures/response_no_url.json"
136137
stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success'"
137-
138+
138139
run "$PWD/hooks/pre-exit"
139140

140141
assert_success

0 commit comments

Comments
 (0)