Skip to content

Commit 48f7f7a

Browse files
authored
Merge pull request #33 from BintLopez/pass_env_var_to_docker
Actually pass the failure output env var to docker
2 parents d3ea335 + 238aad8 commit 48f7f7a

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ cd ruby
6060
rake
6161
```
6262

63+
To test your plugin in your builds prior to opening a pull request, you can refer to your fork and SHA from a branch in your `pipeline.yml`.
64+
65+
```
66+
steps:
67+
- label: Annotate
68+
plugins:
69+
YourGithubHandle/junit-annotate#sha:
70+
...
71+
```
72+
6373
## License
6474
6575
MIT (see [LICENSE](LICENSE))

hooks/command

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ docker \
3030
--volume "$artifacts_dir:/junits" \
3131
--volume "$PLUGIN_DIR/ruby:/src" \
3232
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
33+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_OUTPUT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_OUTPUT:-}" \
3334
ruby:2.5-alpine /src/bin/annotate /junits \
3435
> "$annotation_path"
3536

@@ -39,4 +40,4 @@ if grep -q "<details>" "$annotation_path"; then
3940
echo "--- :buildkite: Creating annotation"
4041
# shellcheck disable=SC2002
4142
cat "$annotation_path" | buildkite-agent annotate --context junit --style error
42-
fi
43+
fi

tests/command.bats

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ load "$BATS_PATH/load.bash"
2020
stub buildkite-agent "artifact download junits/*.xml /plugin/tests/tmp//plugin/junit-artifacts : echo Downloaded artifacts" \
2121
"annotate --context junit --style error : echo Annotation added"
2222

23-
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= ruby:2.5-alpine /src/bin/annotate /junits : echo '<details>Failure</details>'"
23+
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= --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_OUTPUT= ruby:2.5-alpine /src/bin/annotate /junits : echo '<details>Failure</details>'"
2424

2525
run "$PWD/hooks/command"
2626

@@ -33,6 +33,34 @@ load "$BATS_PATH/load.bash"
3333
unstub docker
3434
}
3535

36+
@test "can pass through optional params" {
37+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
38+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN="custom_(*)_pattern.xml"
39+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_OUTPUT="file"
40+
41+
artifacts_tmp="tests/tmp/$PWD/junit-artifacts"
42+
annotation_tmp="tests/tmp/$PWD/junit-annotation"
43+
44+
stub mktemp \
45+
"-d junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX : mkdir -p $artifacts_tmp; echo $artifacts_tmp" \
46+
"-d junit-annotate-plugin-annotation-tmp.XXXXXXXXXX : mkdir -p $annotation_tmp; echo $annotation_tmp"
47+
48+
stub buildkite-agent "artifact download junits/*.xml /plugin/tests/tmp//plugin/junit-artifacts : echo Downloaded artifacts" \
49+
"annotate --context junit --style error : echo Annotation added"
50+
51+
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_OUTPUT='file' ruby:2.5-alpine /src/bin/annotate /junits : echo '<details>Failure</details>'"
52+
53+
run "$PWD/hooks/command"
54+
55+
assert_success
56+
57+
assert_output --partial "Annotation added"
58+
59+
unstub mktemp
60+
unstub buildkite-agent
61+
unstub docker
62+
}
63+
3664
@test "doesn't create annotation unless there's failures" {
3765
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
3866

@@ -45,7 +73,7 @@ load "$BATS_PATH/load.bash"
4573

4674
stub buildkite-agent "artifact download junits/*.xml /plugin/tests/tmp//plugin/junit-artifacts : echo Downloaded artifacts"
4775

48-
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= ruby:2.5-alpine /src/bin/annotate /junits : echo No test errors"
76+
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= --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_OUTPUT= ruby:2.5-alpine /src/bin/annotate /junits : echo No test errors"
4977

5078
run "$PWD/hooks/command"
5179

@@ -54,4 +82,12 @@ load "$BATS_PATH/load.bash"
5482
unstub mktemp
5583
unstub buildkite-agent
5684
unstub docker
57-
}
85+
}
86+
87+
@test "errors without the 'artifacts' property set" {
88+
run "$PWD/hooks/command"
89+
90+
assert_failure
91+
92+
assert_output --partial "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS: unbound variable"
93+
}

0 commit comments

Comments
 (0)