Using Build Meta-data

In this guide we’ll walk through using the Buildkite Agent’s meta-data command to store and retrieve data between different steps in a build pipeline.

Setting data

You can set meta-data via the command line or in a script. Both of these methods use the buildkite-agent cli with the meta-data command.

To set meta-data in the meta-data store, use the set command with a key/value pair:

buildkite-agent meta-data set "release-version" "1.1"

This command results in the value "1.1" being associated with the key "release-version" in the meta-data store.

Getting data

You can retreive data from the meta-data store either via the command line or in a script. The same as when setting data, both of these methods use the buildkite-agent cli with the meta-data command.

Values can only be retreived from the store after it has been set - ensure that any steps that are getting data are guaranteed to run after the completion of the step that sets the data. One way to ensure workflows in this way is to use a wait step.

To retrieve meta-data, use the get command with the previously set key:

buildkite-agent meta-data get "release-version"

Assuming that the "release-version" key was set with the value from the Setting Data example, this command will return "1.1". If there are no keys matching the name "release-version", it will return an error.

Default values

The `get` command has a `default` flag. You can use this to return a value in the case that the key has not been set.

Further documentation

See the Buildkite Agent build meta-data documentation for a full list of options and details of Buildkite’s meta-data support.