# How to set an ENV var for all steps in the pipeline

**URL:** <https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887>\
**Category:** General\
**Created:** [April 25, 2023, 3:39pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887 "2023-04-25T15:39:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![js-cb](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@js-cb](https://forum.buildkite.community/u/js-cb)\
**Post date:** [April 25, 2023, 3:39pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887/1 "2023-04-25T15:39:50Z")

</div>

I though that top-level `env` created environment variables which affected every single step in the pipeline. Example:

```auto
env:
  MYVAR: SomeValue

steps:
  - label: step1
    command: echo $MYVAR

```

Comes up empty.

What is the recommended method of doing this? thanks

---

<div class="post-metadata">

**Author:** ![stephanie.atte](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/stephanie.atte/32/1357_2.png) [@stephanie.atte](https://forum.buildkite.community/u/stephanie.atte)\
**Post date:** [April 25, 2023, 3:52pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887/2 "2023-04-25T15:52:59Z")

</div>

Hello @js-cb🙂  
Thanks for reaching out!

I tried this on my end it works fine.

**pipeline.yml**

```auto
env: 
  MYVAR: "SomeValue"
  
steps:
  - label: "step1"
     command: "echo $MYVAR"

```

Setting the env variable before steps makes it global and available to all steps. You can confirm this by checking the Environment tab it should have `MYVAR="SomeValue"` as a variable set.

Let me know if this helps!  
Cheers  
Stephanie

---

<div class="post-metadata">

**Author:** ![js-cb](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@js-cb](https://forum.buildkite.community/u/js-cb)\
**Post date:** [April 25, 2023, 3:55pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887/3 "2023-04-25T15:55:39Z")

</div>

i @stephanie.atte  
Is your buildkite running a different version than mine? (I don’t even know if there’s such a thing)

I have set that in 2 places: the pipeline yml and the pipeline “pre” steps which load the actual yml  
Neither of them kick in

---

<div class="post-metadata">

**Author:** ![js-cb](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@js-cb](https://forum.buildkite.community/u/js-cb)\
**Post date:** [April 25, 2023, 3:58pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887/4 "2023-04-25T15:58:50Z")

</div>

I went back to hardcoded env vars for every step. That works regardless. But it would be nice to find out why the other way does not work

---

<div class="post-metadata">

**Author:** ![stephanie.atte](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/stephanie.atte/32/1357_2.png) [@stephanie.atte](https://forum.buildkite.community/u/stephanie.atte)\
**Post date:** [April 25, 2023, 4:05pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887/5 "2023-04-25T16:05:16Z")

</div>

Hey @js-cb I’m using buildkite-agent version 3.42.0 . Can you check which version you are running might be an older version, use " buildkite-agent --v " . Incase its an older agent you can get a newer one , under the respective agent installer

> **[The Buildkite Agent v3](https://buildkite.com/docs/agent/v3)**
>
> The Buildkite agent is a small, reliable and cross-platform build runner that makes it easy to run automated builds on your own infrastructure. Its main responsibilities are polling buildkite.com for work, running build jobs, reporting back the...

I can also take a closer look at the build for you, please send the build link to [support@buildkite.com](mailto:support@buildkite.com)

---

<div class="post-metadata">

**Author:** ![js-cb](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@js-cb](https://forum.buildkite.community/u/js-cb)\
**Post date:** [April 25, 2023, 4:13pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887/6 "2023-04-25T16:13:33Z")

</div>

> [@stephanie.atte](#):
>
> buildkite-agent --v

Our version is 3.40.0

---

<div class="post-metadata">

**Author:** ![stephanie.atte](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/stephanie.atte/32/1357_2.png) [@stephanie.atte](https://forum.buildkite.community/u/stephanie.atte)\
**Post date:** [April 25, 2023, 4:19pm UTC](https://forum.buildkite.community/t/how-to-set-an-env-var-for-all-steps-in-the-pipeline/2887/7 "2023-04-25T16:19:23Z")

</div>

Hmm @js-cb that’s strange. Please send an email with a link to the build to [support@buildkite.com](mailto:support@buildkite.com) , I’m curious to see, what’s causing this as well
