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

**URL:** <https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089>\
**Category:** General\
**Created:** [June 10, 2022, 3:42am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089 "2022-06-10T03:42:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [June 10, 2022, 3:42am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089/1 "2022-06-10T03:42:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [June 10, 2022, 3:44am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089/2 "2022-06-10T03:44:20Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [June 10, 2022, 3:46am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089/3 "2022-06-10T03:46:18Z")

</div>

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](https://buildkite.com/docs/agent/v3/cli-meta-data#getting-data-options)

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [June 10, 2022, 3:53am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089/4 "2022-06-10T03:53:02Z")

</div>

Hi, jarryd Can i do it like

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

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

```

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [June 10, 2022, 4:04am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089/5 "2022-06-10T04:04:39Z")

</div>

> [@paula](#):
>
> –default

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

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [June 10, 2022, 4:10am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089/6 "2022-06-10T04:10:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [June 10, 2022, 4:10am UTC](https://forum.buildkite.community/t/how-to-make-buildkite-agent-meta-data-get-key-optional/2089/7 "2022-06-10T04:10:56Z")

</div>

Thank you very much,
