How to make buildkite-agent meta-data get "key" optional

We have this script that create build for different pipeline and we added an input step to one of the pipeline So we are getting buildkite-agent meta-data get “” does not exist error from other pipeline

How do you do this in bash?
How to check if numberOfBuild key exist and if it exist pass the value if not dont?

build=${buildkite-agent meta-data get numberOfBuild-""}

Hey @Joe

Meta data is scoped to a build so if you are trying to access it from another build or pipeline, you need to pass the --job field to the command.
There is also a --default field for the get operation that will be returned if the key does not exist.

You can check out more info in the docs on the meta-data command at buildkite-agent meta-data v3 | Buildkite Documentation

Hi, jarryd Can i do it like

numberOfBuild=$(buildkite-agent meta-data exist numberOfScratchOrg)

if [ "$checkKeyExist" -eq 0 ]; then
    build=$(buildkite-agent meta-data get numberOfBuild)

Hi, jarryd, again, In the default can i pass an empty string instead?
build=$(buildkite-agent meta-data get numberOfBuild --default “”

Yeah I’d say if you are quoting an empty string, the agent CLI won’t really care what the value is so that should work

Thank you very much,

1 Like