buildkite / buildkite/agent

Trailing newline may be missing when getting meta-data

Open
#1,144 0 comments 0 reactions 0 assignees View on GitHub
meta-data
Dominant language
Go
Stars
1.1k
Forks
378
Avg merge
2d 6h
Merged PRs (30d)
74

Description

When using a block step with a select-input and `multiple=true`, the keys of the selected options are set as meta-data with line-breaks as delimiters. Unfortunately, the last line is missing a trailing line-break. This can be quite error-prone when scripting in a POSIX shell, since the straightforward construction will [silently leave the final line unprocessed](https://stackoverflow.com/a/12916758):
```bash
buildkite-agent meta-data get selected_options | while read -r selection; do
echo "$selection was selected"
done
```

The [documentation](https://buildkite.com/docs/pipelines/block-step) is not clear imo on whether this behavior is intentional:
> When multiple options are selected, they are delimited in the meta-data field by a line break (\n).

It is in any case not consistent, since `buildkite-agent meta-data keys` uses also a `\n` as delimiter but includes a trailing `\n` as well.

It would probably a good idea if `buildkite-agent meta-data get` would always output a trailing new-line (on non-empty output, at least). I see how this could be potentially breaking for some people, maybe it could be protected by a flag.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.