Passing arguments to pipeline

Hi :waving_hand:

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:

commands:
  - |
    cat <<YAML | buildkite-agent pipeline upload
    steps:
      - trigger: "some-other-pipeline"
        build:
          env:
            MY_ARG: "$(buildkite-agent meta-data get my_arg)"
    YAML

but that looks truly gruesome :slightly_smiling_face:

Is there a better way of achieving the same effect as the above?

Thanks!

Hello @savvas

Welcome to the community :tada: !

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.

steps:
  - command: 'buildkite-agent meta-data set "my_arg" "1.1"'
  - wait
  - label: "Generate trigger step"
    command: |
      cat <<YAML | buildkite-agent pipeline upload
      steps:
        - trigger: "some-other-pipeline"
          build:
            env:
              MY_ARG: "$(buildkite-agent meta-data get "my_arg")"
      YAML