# How are pipeline env blocks merged on pipeline uploads?

**URL:** https://forum.buildkite.community/t/how-are-pipeline-env-blocks-merged-on-pipeline-uploads/2821
**Category:** Pipelines
**Created:** [April 5, 2023, 7:38pm UTC](https://forum.buildkite.community/t/how-are-pipeline-env-blocks-merged-on-pipeline-uploads/2821 "2023-04-05T19:38:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pbarrau](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pbarrau](https://forum.buildkite.community/u/pbarrau)
#### Post date: [April 5, 2023, 7:38pm UTC](https://forum.buildkite.community/t/how-are-pipeline-env-blocks-merged-on-pipeline-uploads/2821/1 "2023-04-05T19:38:05Z")

</div>

Let’s consider the following pipeline definitions:

p1.yml:

```auto
env:
    FOO="bar"

steps:
    (...)

```

p2.yml:

```auto
env:
    FOO="baz"

steps:
    (...)

```

If I configure a dynamic pipeline with a step performing:

```auto
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?

---

<div class="post-metadata">

### Author: ![jeremy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jeremy/32/1040_2.png) [@jeremy](https://forum.buildkite.community/u/jeremy)
#### Post date: [April 5, 2023, 8:42pm UTC](https://forum.buildkite.community/t/how-are-pipeline-env-blocks-merged-on-pipeline-uploads/2821/2 "2023-04-05T20:42:53Z")

</div>

Hey @pbarrau 👋

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

Given the following pipeline YAML and steps:

Steps:

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

```

p1.yml

```auto
env:
  FOO: "bar"

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

```

p2.yml

```auto
env:
  FOO: "bar"

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

```

The resulting build would look like this:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/c/c6736c74be0d4bab77f74ca3d6cc40a3030a36c7.png)

---

<div class="post-metadata">

### Author: ![pbarrau](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pbarrau](https://forum.buildkite.community/u/pbarrau)
#### Post date: [April 10, 2023, 5:05pm UTC](https://forum.buildkite.community/t/how-are-pipeline-env-blocks-merged-on-pipeline-uploads/2821/3 "2023-04-10T17:05:49Z")

</div>

Hi @jeremy

I reproduced your test:

Steps:

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

```

p1.yml:

```auto
env:
  FOO: "bar"

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

```

p2.yml:

```auto
env:
  FOO: "baz"

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

```

But got different results:

 ![Screenshot 2023-04-10 at 11.03.26](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/e/ecaee51231766192719b360b18effcccb56c0ccb.png)

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

---

<div class="post-metadata">

### Author: ![suma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/suma/32/1306_2.png) [@suma](https://forum.buildkite.community/u/suma)
#### Post date: [April 10, 2023, 7:54pm UTC](https://forum.buildkite.community/t/how-are-pipeline-env-blocks-merged-on-pipeline-uploads/2821/4 "2023-04-10T19:54:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![pbarrau](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pbarrau](https://forum.buildkite.community/u/pbarrau)
#### Post date: [April 10, 2023, 8:14pm UTC](https://forum.buildkite.community/t/how-are-pipeline-env-blocks-merged-on-pipeline-uploads/2821/5 "2023-04-10T20:14:36Z")

</div>

@suma Got it. Thanks for the confirmation.
