# Passing variables to other steps

**URL:** <https://discuss.circleci.com/t/passing-variables-to-other-steps/27700>\
**Category:** Build Environment\
**Created:** [January 16, 2019, 8:15pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700 "2019-01-16T20:15:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalefrancum-ncino](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dalefrancum-ncino/32/9110_2.png) [@dalefrancum-ncino](https://discuss.circleci.com/u/dalefrancum-ncino)\
**Post date:** [January 16, 2019, 8:15pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/1 "2019-01-16T20:15:51Z")

</div>

To this point, the only way I’ve been able to pass a variable (for example, a token) from one step to another is to write a file which contains that value.

This has been asked on here before, but I just want to check again and see if anything has changed and/or if others have come up with more elegant methods of doing this.

Thanks.

---

<div class="post-metadata">

**Author:** ![dalefrancum-ncino](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dalefrancum-ncino/32/9110_2.png) [@dalefrancum-ncino](https://discuss.circleci.com/u/dalefrancum-ncino)\
**Post date:** [January 16, 2019, 8:19pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/2 "2019-01-16T20:19:48Z")

</div>

I’m considering giving this a try:

> **[damphat/kv-bash](https://github.com/damphat/kv-bash)**
>
> key/value database written in bash script (permanent variables in shell) - damphat/kv-bash

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [January 16, 2019, 8:58pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/3 "2019-01-16T20:58:40Z")

</div>

I assume you’ve tried it: can you set environment variables in one step and read them in another? I have the vague recollection I’ve done that with CircleCI, but I could be wrong.

---

<div class="post-metadata">

**Author:** ![dalefrancum-ncino](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dalefrancum-ncino/32/9110_2.png) [@dalefrancum-ncino](https://discuss.circleci.com/u/dalefrancum-ncino)\
**Post date:** [January 17, 2019, 2:07am UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/4 "2019-01-17T02:07:47Z")

</div>

No, if you set an environment variable in a step, it is local to that step. If I understand correctly, each step is run under its own bash command.

You can set environment variables per build, container, etc., and those are accessible throughout a job, but that’s not what I have in mind for this.

Thanks for the response.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [January 17, 2019, 9:00am UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/5 "2019-01-17T09:00:52Z")

</div>

Can you do `export VAR=value` in a step? I’ve not got an example to hand, but I wonder whether it would help.

---

<div class="post-metadata">

**Author:** ![apeschel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/apeschel/32/23468_2.png) [@apeschel](https://discuss.circleci.com/u/apeschel)\
**Post date:** [March 14, 2019, 8:59pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/6 "2019-03-14T20:59:08Z")

</div>

That won’t work, each step is its own shell and the environment variables don’t carry over.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 14, 2019, 9:02pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/7 "2019-03-14T21:02:27Z")

</div>

> [@apeschel](#):
>
> each step is its own shell and the environment variables don’t carry over

Gotcha. What’s your use case? Maybe you can just use a file in the tmp directory.

---

<div class="post-metadata">

**Author:** ![apeschel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/apeschel/32/23468_2.png) [@apeschel](https://discuss.circleci.com/u/apeschel)\
**Post date:** [March 14, 2019, 9:05pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/8 "2019-03-14T21:05:35Z")

</div>

CircleCI just has terrible support for passing information from one step to another. Here’s the relevant documentation with their recommended workaround:

[https://circleci.com/docs/2.0/env-vars/#using-bash\_env-to-set-environment-variables](https://circleci.com/docs/2.0/env-vars/#using-bash_env-to-set-environment-variables)

---

<div class="post-metadata">

**Author:** ![apeschel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/apeschel/32/23468_2.png) [@apeschel](https://discuss.circleci.com/u/apeschel)\
**Post date:** [March 14, 2019, 9:07pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/9 "2019-03-14T21:07:40Z")

</div>

The corner CircleCI has painted itself into, however, is that you can’t really use a BASH\_ENV to pass a parameter to an orb or command. I’m not sure there’s actually any way to pass an interpolated value as a parameter to a command or an orb with the current set up.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 14, 2019, 9:36pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/10 "2019-03-14T21:36:01Z")

</div>

> [@apeschel](#):
>
> CircleCI just has terrible support

> [@apeschel](#):
>
> The corner CircleCI has painted itself into

My advice is that if you are this negative about any CI system, your CI project will fail - a positive mental attitude (and an inclination towards pragmatism) is essential to get it working and finished. If you want something that fits your use-case exactly, install Jenkins and maintain it yourself.

(I tend towards the view that hosted systems save time and frustration in the long run, even when taking work-arounds into account).

---

<div class="post-metadata">

**Author:** ![apeschel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/apeschel/32/23468_2.png) [@apeschel](https://discuss.circleci.com/u/apeschel)\
**Post date:** [March 14, 2019, 10:42pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/11 "2019-03-14T22:42:12Z")

</div>

A positive attitude still won’t let you pass interpolated values to a command or orb, no matter how intensely positive it is.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 14, 2019, 10:43pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/12 "2019-03-14T22:43:21Z")

</div>

Ha ha, true @apeschel 🤣

However, it might help you find a workaround… 🤔

---

<div class="post-metadata">

**Author:** ![dalefrancum-ncino](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dalefrancum-ncino/32/9110_2.png) [@dalefrancum-ncino](https://discuss.circleci.com/u/dalefrancum-ncino)\
**Post date:** [March 14, 2019, 10:53pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/13 "2019-03-14T22:53:40Z")

</div>

I meant to follow up on this before, but apeschel actually posted the link to what I ended up doing anyway. It’s not elegant, but it works, at least for our use case.

I disagree about CircleCI having terrible support. They’ve always been very responsive for us whenever we submit a ticket or email a rep.

---

<div class="post-metadata">

**Author:** ![apeschel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/apeschel/32/23468_2.png) [@apeschel](https://discuss.circleci.com/u/apeschel)\
**Post date:** [March 14, 2019, 11:34pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/14 "2019-03-14T23:34:28Z")

</div>

I don’t think anyone is criticizing CircleCI support. The support quote was taken out of context. It was meant to point out specifically that the CircleCI platform has poor support for the specific feature of passing information between job steps.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [March 15, 2019, 2:14pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/15 "2019-03-15T14:14:32Z")

</div>

> [@apeschel](#):
>
> I’m not sure there’s actually any way to pass an interpolated value as a parameter to a command or an orb with the current set up.

I believe this feature request [https://ideas.circleci.com/ideas/CCI-I-67](https://ideas.circleci.com/ideas/CCI-I-67) is what you are referring to.

To @dalefrancum-ncino I’m glad the workaround works for you.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 13, 2019, 2:14pm UTC](https://discuss.circleci.com/t/passing-variables-to-other-steps/27700/16 "2019-06-13T14:14:36Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
