trying to implement very simple use case…
Group 1, Step
buildkite-agent meta-data set ENV $DEFAULT_ENV
Group 2, Step
buildkite-agent meta-data get ENV
var=$(buildkite-agent meta-data get ENV)
echo “->” $var
It seems that command “buildkite-agent meta-data get” works but I cannot assign it to var
Any idea ? Thanks
Agent is running on MacOS, buildkite-agent version 3.57.0+x.78b37076ce6362a0c3f700edcbd0bdcf9f22d2d8
Thanks for the question - and welcome to the Buildkite Forum!
I’m assuming you’d want to keep this within the Step editor? Since these commands are all done within processes (with PIDs) - you could do something like this (assuming its a similar approach!) - note the
- group: "Group 1"
- label: ":cd: Setting env"
buildkite-agent meta-data set env $ENV
- group: "Group 2"
- label: ":printer: Export/obtaining var1"
export var1=$(buildkite-agent meta-data get env)
Keep in mind,
var1 will only be available to that job itself (from the
export) - you could run this all in a script to a similar effect too, this is the assumption its all kept inside the group step as above.
Another way you could go around this is using build level environment variables, so something like
at the start of the pipeline, and use $ENVIRONMENT through the build (this can also be set at the start of the build too, so for example,
ENVIRONMENT: $ENVIRONMENT (and set
ENVIRONENT=xyz in the Environment Variables section on a new build through the UI/set in the payload within the API:
Hope that helps!
It is working : i missed interpolation to manipulate variable after meta-data get
why do we need it ?
Interpolation happens at upload time, so in this case when you are trying to use $var is actually evaluated before the build starts running and at that time, the step to set the variable hasn’t run, so it ends up being empty.
You can read more about variable interpolation in our docs