agent icon indicating copy to clipboard operation
agent copied to clipboard

Prevent STDERR warnings for metadata get with --default

Open toolmantim opened this issue 6 years ago • 3 comments

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?

toolmantim avatar Aug 16 '19 03:08 toolmantim

How about a --silent or --log-level=none or similar?

lox avatar Aug 16 '19 03:08 lox

(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

craigds avatar Aug 16 '19 03:08 craigds

Oh yeah, true, the warning is unneeded. I'll do that and also a --silent flag. Sorry you ran into this @craigds

lox avatar Aug 16 '19 03:08 lox