I am trying to pass some arguments from one pipeline to another using a trigger step but I am unable to do so.
Suppose the following (abridged) trigger step:
- trigger: "some-other-pipeline"
label: "My step label"
build:
env:
MY_ARG: "$(buildkite-agent meta-data get my_arg)"
The intention here is to set MY_ARG with whatever value was set to my_arg with the buildkite-agent meta-data get set command in the same pipeline and pass that through to some-other-pipeline.
That however doesn’t work and MY_ARG always ends up with an empty value in some-other-pipeline because I believe shell commands aren’t getting executed inside the env section?
One solution that works is doing something similar to:
Your understanding is correct. Shell commands aren’t evaluated in a static trigger step’s env block it’s treated as pipeline config, not shell input, so $(buildkite-agent meta-data get "my_arg") won’t run there, leaving MY_ARG empty.
Your dynamic pipeline upload approach is the best and recommended approach for runtime values , so the resolved value (e.g. MY_ARG: "1.1") gets passed through as seen in my example below.
I’ve noticed that static arguments declared either in an env block at the top of the pipeline file or even in a select block are also visible within the trigger block using the {metaenv?.MY_VAR} syntax but I guess this isn’t shell but rather buildkite level resolution?
@savvas that’s correct; we’re essentially using a YAML parser via Ruby to determine what the values are on the pipeline where input and env are being set, then interpolating those values in the pipeline YAML.