Env vars from project vs. circle.yml


#1

Hi,

Is there a way to make project defined environment variables available to environment variables being set in the machine: environment: section of a circle.yml file?

I’d like to set an environment variable in my circle.yml based on one defined in the CircleCI project. If that makes sense?

Thanks

Martin


#2

The circle.yml file allows bash, so you should just be able to reference the env in it the way you would normally. Each command runs a separate shell though, so you will need to make sure it’s set somewhere like your .bashrc file so bash can find it.


#3

Let me give an example; I have a project in which I have configured (under Project Settings - Build Settings) an Environment Variable called MY_ENV with a value of ‘Foo’. In my circle.yml file I then have:

machine:
    environment:
        ENV1: "$(if [ <SOME_CONDITION> ]; then echo Bar; else echo $MY_ENV; fi)"

I’ve found that if <SOME_CONDITION> evaluates to false then ENV1 has a blank value (rather than the intended value of ‘Foo’).

Looking at the build output, under the ‘MACHINE’ section I see ‘Exporting env vars from circle.yml’. After that I see ‘Exporting env vars from project settings’. To me, this suggests that any environment variables defined in Project Settings - Build Setting will not be available to the machine - environment section of the circle.yml.

Unless there’s a way to do some sort of lazy evaluation…


#4