There’s a value that gets calculated mid-way through my build (during the 4th step, to be precise). It’s just a simple short string. I’d like to include that value in the message text of a Slack notification that gets sent when the build finishes.
The value was previously only saved as an artifact (a text file), using buildkite-agent artifact upload "foo_mode.txt" . I figured it wouldn’t be possible to grab the contents of an artifact for the notification text, so I’ve made it also get saved as meta-data, using buildkite-agent meta-data set “foo-mode” “${FOO_MODE}” .
Currently I’m trying this in my build steps yaml (just after steps:):
Env interpolation will only work there if the env itself is already set; but it won’t be set if the env: is in the same YAML as the notification. I’m not sure there’s a way for the meta-data interpolation to work there
Yes, that’s what I thought, that a given value has to be passed as an environment variable.
So I guess a better question for me to ask might be: is there any way that a value calculated during the build (i.e. it’s not available at the very start of the build) can be set as an environment variable, which would then be available for interpolation in the notification yaml?
Did anyone work out how to inline meta data in the notifications? We also set a variable in a step that would be very useful in the slack notification so that it is not so generic.
So you basically generate your pipeline yaml through this script along with the message for your notify. I hope this helps with your question and please feel free to let us know if you have any follow up questions.
Thank you. That worked. We had to leave some failure notifications as non-stepped notify without the meta-data but our happy flows now include notifications with the meta-data.
(PS we changed from ’ to " and \ " so that the variable interpolation worked in the shell script, and also YAML indentations in the echos)