agent
agent copied to clipboard
Prevent STDERR warnings for metadata get with --default
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:
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:
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:
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?
How about a --silent or --log-level=none or similar?
(This was on my behalf via a support ticket.)
This isn't really a buildkite agent issue, it turns out - I was just using docker wrong.
I've just realised the -t option to docker was breaking this. Removing it seems to fix the problem. The docs are hard to understand.
I do think the warning is unnecessary - if the user chose a --default it should just use the default :)
But feel free to close this. Thanks
Oh yeah, true, the warning is unneeded. I'll do that and also a --silent flag. Sorry you ran into this @craigds