Use Environment Variables in Conditional Step

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 Likes

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

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

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?

I think it might be this.

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.

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?

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.

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.

1 Like

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.

2 Likes

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