Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ Upload test results to Test Engine. Default: `true`. Set to `false` if you use t

Requires bktec 2.7.0 or later.

#### `tags` (optional, array of strings)

Tags to attach to the uploaded test results. Each tag is a `key=value` string.

```yaml
plugins:
- tests#v1.0.0:
test-runner: rspec
tags:
- "language.version=3.3"
- "os=linux"
```

#### `debug-enabled` (optional, boolean)

Enable verbose output.
Expand Down
19 changes: 19 additions & 0 deletions hooks/environment
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ for prop in "${PROPERTIES[@]}"; do
fi
done

# Buildkite exposes array properties as indexed env vars (TAGS_0, TAGS_1, ...),
# but a single string value is exposed without an index (TAGS). So we need to handle both.
if [[ -n "${BUILDKITE_PLUGIN_TESTS_TAGS:-}" ]]; then
export "BUILDKITE_TEST_ENGINE_TAGS=${BUILDKITE_PLUGIN_TESTS_TAGS}"
exported_vars+=("BUILDKITE_TEST_ENGINE_TAGS")
elif [[ -n "${BUILDKITE_PLUGIN_TESTS_TAGS_0:-}" ]]; then
declare -a tags=()
i=0
while true; do
plugin_var="BUILDKITE_PLUGIN_TESTS_TAGS_${i}"
[[ -z "${!plugin_var:-}" ]] && break
tags+=("${!plugin_var}")
i=$(( i + 1 ))
done
joined=$(IFS=','; echo "${tags[*]}")
export "BUILDKITE_TEST_ENGINE_TAGS=$joined"
exported_vars+=("BUILDKITE_TEST_ENGINE_TAGS")
fi

# TODO:
# Update docker and docker-compose plugins to propagate these env vars
# so we don't have to write them to BUILDKITE_ENV_FILE here.
Expand Down
6 changes: 6 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ configuration:
description: >-
Upload test results to Test Engine. Default: true. Set to false if you use the test collectors for richer
data collection, or if you want to handle the upload yourself.
tags:
type: array
description: >-
Tags to attach to the uploaded test results. Each tag is a key=value string (e.g. "env=production").
items:
type: string

# Test runner
test-runner:
Expand Down
40 changes: 40 additions & 0 deletions tests/environment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,43 @@ setup() {
run cat ${BUILDKITE_ENV_FILE}
assert_output "BUILDKITE_TEST_ENGINE_UPLOAD_RESULTS=false"
}

@test "passes a tag string directly to bktec" {
export BUILDKITE_PLUGIN_TESTS_TAGS="language.version=3.3"
export BUILDKITE_ENV_FILE=$(mktemp)

run $PWD/hooks/environment

run cat ${BUILDKITE_ENV_FILE}
assert_line "BUILDKITE_TEST_ENGINE_TAGS=language.version=3.3"
}

@test "passes a single tag to bktec" {
export BUILDKITE_PLUGIN_TESTS_TAGS_0="language.version=3.3"
export BUILDKITE_ENV_FILE=$(mktemp)

run $PWD/hooks/environment

run cat ${BUILDKITE_ENV_FILE}
assert_line "BUILDKITE_TEST_ENGINE_TAGS=language.version=3.3"
}

@test "passes multiple tags to bktec as comma-separated values" {
export BUILDKITE_PLUGIN_TESTS_TAGS_0="language.version=3.3"
export BUILDKITE_PLUGIN_TESTS_TAGS_1="os=linux"
export BUILDKITE_ENV_FILE=$(mktemp)

run $PWD/hooks/environment

run cat ${BUILDKITE_ENV_FILE}
assert_line "BUILDKITE_TEST_ENGINE_TAGS=language.version=3.3,os=linux"
}

@test "does not set tags env var when no tags provided" {
export BUILDKITE_ENV_FILE=$(mktemp)

run $PWD/hooks/environment

run cat ${BUILDKITE_ENV_FILE}
refute_line --partial "BUILDKITE_TEST_ENGINE_TAGS"
}