How are pipeline env blocks merged on pipeline uploads?

Let’s consider the following pipeline definitions:

p1.yml:

env:
    FOO="bar"

steps:
    (...)

p2.yml:

env:
    FOO="baz"

steps:
    (...)

If I configure a dynamic pipeline with a step performing:

buildkite-agent pipeline upload p1.yml
buildkite-agent pipeline upload p2.yml

What will the value of the FOO env var be in the generated pipeline?

Hey @pbarrau :wave:

Great question! The value of FOO will reflect the env configuration in the uploaded pipeline YAML.

Given the following pipeline YAML and steps:

Steps:

steps:
  - command: |
      buildkite-agent pipeline upload .buildkite/p1.yml
      buildkite-agent pipeline upload .buildkite/p2.yml

p1.yml

env:
  FOO: "bar"

steps:
  - command: echo "+++ p1 - $$FOO"

p2.yml

env:
  FOO: "bar"

steps:
  - command: echo "+++ p1 - $$FOO"

The resulting build would look like this:

Hi @jeremy

I reproduced your test:

Steps:

steps:
  - command: |
      buildkite-agent pipeline upload .buildkite/p1.yml
      buildkite-agent pipeline upload .buildkite/p2.yml

p1.yml:

env:
  FOO: "bar"

steps:
  - command: echo "+++ p1 - $$FOO"

p2.yml:

env:
  FOO: "baz"

steps:
  - command: echo "+++ p2 - $$FOO"

But got different results:

Should I conclude that there is a typo in your message, or that the behavior depends on other external factors?

Hi @pbarrau

This is Suma jumping in on behalf of Jeremy. Yes, you are correct there was a typo in the message.

If the pipeline uploads are run concurrently, then the value of FOO will match the uploading pipeline YAML. If the pipeline uploads are run serially, then the latest declaration will be true (FOO=“baz”)

I hope this explains the behavior in this scenario.

@suma Got it. Thanks for the confirmation.