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 $$ interpolation:
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
env:
ENVIRONMENT: production
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:
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