Use Environment Variables in Conditional Step


#1

I am trying to:

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?


#2

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


#3

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


#4

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?


#5

I think it might be this.


#6

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.


#7

I believe I understand what you have written, but if you have not written what you mean, then yes, it will be confusing. :rofl: 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?


#8

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.


#9

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.


#10

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.