# Use Environment Variables in Conditional Step

**URL:** <https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658>\
**Category:** Tips, Tricks, and Hacks\
**Created:** [January 15, 2019, 6:36am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658 "2019-01-15T06:36:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![maurocolella](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/maurocolella/32/21127_2.png) [@maurocolella](https://discuss.circleci.com/u/maurocolella)\
**Post date:** [January 15, 2019, 6:36am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/1 "2019-01-15T06:36:35Z")

</div>

I am trying to:

```auto
steps:
  - when:
      condition: "$SOME_ENV_VAR"
      steps:

```

Where `$SOME_ENV_VAR` would be a string of some sort.

Is that possible?  
Is something similar planned?  
Is there a workaround?

---

<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 15, 2019, 8:55am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/2 "2019-01-15T08:55:49Z")

</div>

Is this a boolean var, e.g. `0` or `1`? Or is it an expression, e.g. `4 < 5`?

---

<div class="post-metadata">

**Author:** ![maurocolella](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/maurocolella/32/21127_2.png) [@maurocolella](https://discuss.circleci.com/u/maurocolella)\
**Post date:** [January 15, 2019, 9:07am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/3 "2019-01-15T09:07:16Z")

</div>

It’s numeric, so it can quite easily be made to fit either.

---

<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 15, 2019, 9:08am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/4 "2019-01-15T09:08:55Z")

</div>

Righto. I’ve not tried this. I recall that the implementation of environment variable interpolation is inconsistent around the various features of the YAML file, but that there is a work-around that has been mentioned on this forum. Perhaps that is worth a try?

---

<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 15, 2019, 9:10am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/5 "2019-01-15T09:10:40Z")

</div>

I think [it might be this](https://discuss.circleci.com/t/how-do-i-dynamically-get-the-environment-variables-value-based-on-my-branch-variable-name/17590/2?u=halfer).

---

<div class="post-metadata">

**Author:** ![maurocolella](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/maurocolella/32/21127_2.png) [@maurocolella](https://discuss.circleci.com/u/maurocolella)\
**Post date:** [January 15, 2019, 9:19am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/6 "2019-01-15T09:19:27Z")

</div>

The question is not about the environment variable.

The question is about the conditional step.

Please make sure that you fully understand the question. Variable interpolation is a whole different topic I have no problem with.

---

<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 15, 2019, 6:04pm UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/7 "2019-01-15T18:04:11Z")

</div>

I believe I understand what you have written, but if you have not written what you mean, then yes, it will be confusing. 🤣 Would you like to make any clarifications?

Environment variable interpolation seems to be key to your question, since the string `"$SOME_ENV_VAR"` uses environment variable interpolation. You appear to be asking whether this value will be injected by the conditional step processor, rather than read as a plain, literal string. Is that not the case?

---

<div class="post-metadata">

**Author:** ![maurocolella](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/maurocolella/32/21127_2.png) [@maurocolella](https://discuss.circleci.com/u/maurocolella)\
**Post date:** [January 16, 2019, 2:26am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/8 "2019-01-16T02:26:57Z")

</div>

I am asking if **conditional steps** can make use of environment variables, which the documentation states they can’t.

The question is: “Use Environment Variables **in Conditional Steps** ”. The variable is merely wrapped this way as a best practice in case it is empty - interpolation is really the least possible concern and far removed from the question.

---

<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, 7:26pm UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/9 "2019-01-16T19:26:00Z")

</div>

Please consider that your tone can reasonably be interpreted as hostile - twice now - and that I’m just a volunteer. If you can approach a discussion with levity and kindness, it really does help in public fora! I wish you luck in resolving your problem.

---

<div class="post-metadata">

**Author:** ![maurocolella](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/maurocolella/32/21127_2.png) [@maurocolella](https://discuss.circleci.com/u/maurocolella)\
**Post date:** [January 17, 2019, 1:25am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/10 "2019-01-17T01:25:42Z")

</div>

I understand, and I appreciate your willingness to help, sorry for that.

Unfortunately these answers have been, how can I say? “False positives”. On my end, there is a concern with targets. I need to meet them because - project.

About that:

The CircleCI documentation seems to say that “when (conditional)” steps can only receive parameters, because these have to be resolved at parse-time, and not runtime.

To work around this limitation we’ve had to wrap build steps in shell scripts, and render what’s inside those scripts conditional. Not ideal.

We’ve also had to use shareable git hooks, to further orient our workflow: pick stuff depending on what is compiled.

It all adds up. But I just was hoping for something a little less involved than that.

---

<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:** [April 17, 2019, 1:25am UTC](https://discuss.circleci.com/t/use-environment-variables-in-conditional-step/27658/11 "2019-04-17T01:25:42Z")

</div>

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