buildkite / buildkite/agent

Prevent STDERR warnings for metadata get with --default

Open
#1,077 3 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

If you're getting non-existent build metadata with a `--default` via Docker, you end up with the STDERR combined in the output of the default value.

For example, without Docker you can do this:

```shell
output=$(buildkite-agent meta-data get foo --default default-foo)
# Warnings are printed to STDERR
echo $output
#=> "default-foo"
```

But when you use Docker run, Docker smooshes together STDOUT and STDERR into the STDOUT stream of the run command, and you end up with the warning in the output:

```shell
output=$(
docker run \
-e BUILDKITE_BUILD_ID \
-e BUILDKITE_JOB_ID \
-e BUILDKITE_AGENT_ACCESS_TOKEN \
-t --rm \
buildkite/agent:3 \
buildkite-agent meta-data get foo --default default-foo
)

echo $output
#=> "2019-08-16 03:36:28 WARN No meta-data value exists with key `foo`, returning the supplied default "default-foo""
```

A workaround is to use bash to redirect STDERR:

```shell
output=$(
docker run \
-e BUILDKITE_BUILD_ID \
-e BUILDKITE_JOB_ID \
-e BUILDKITE_AGENT_ACCESS_TOKEN \
-t --rm \
--entrypoint '' \
buildkite/agent:3 \
bash -e -c 'buildkite-agent meta-data get foo --default default-foo 2>/dev/null'
)

echo $output
#=> "default-foo"
```

It'd be nice to perhaps not output a warning at all in the case of using `--default`, or if it's kept then an option for ignoring warning logs?

Contributor guide

Open the contributing guide

Research direction

Start with the `buildkite-agent meta-data get --default` entry point and reproduce the behavior through the Docker invocation shown. Determine the intended warning behavior when a supplied default is returned, then verify that captured Docker output matches the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.