I have a BuildKite pipeline with two command steps and a block step in-between. Among other things, the first command step gathers a bunch of information and puts it into environment variables. Then the block runs and asks the user to continue. Assuming approved, the second command runs but does not have the previously-set environment variables (separate step, could be separate agent, etc.).
Simplest reproducible:
steps:
- label: "Test setting variable"
command: |
export MY_VAR=SomeValue
- wait: ~
- label: "Test using variable"
command: |
echo MY_VAR=$$MY_VAR
Is there any way to tell BuildKite to add exported environment variables to the pipeline-wide variables? I have a wait
so the second step will not run until the first finishes.
I realize I can use buildkite-agent meta-data set/get
. I'll do that if there is no better way.
Thank you.
You can have a global
env
section for the whole pipeline:Variables set here are available to all steps.
Not sure you have the values you want to set at that point though, sounds like the values are only calculated in the step.
As an alternative you can try export the values into a file, store the file as an artifact and then restore it in the desired step:
This is an untested pseudo-code but I was using something similar to fix the same problem in Bitbucket pipelines and it worked well.