How to export env variables in circleci? (You wont find this in circleci documentation)

According to the circleci documentation i should echo commands into $BASH_ENV in order to interpolate variables


Unfortunately, does not seem to work.

Solution: we have to explicitly do source $BASH_ENV before each job that relies on it

            name: python/default
            tag: '3.9'
        - checkout
        - run:
            name: source bash env
            command: |
                echo 'export TF_VAR_ENVIRONMENT="${ENVIRONMENT}"' >> $BASH_ENV
                source $BASH_ENV

Each step runs in its own shell, so if you have commands that depend on runtime definition of an environment variable, your only option is to combine those commands into a single step.

Note: BASH_ENV is purely bash-thing. So for example if you use alpine based docker image, which has dash by default, it will not work.

Written by - Dishant Sethi


Enjoyed the blog? If so, you'll appreciate collaborating with the minds behind it as well.

Last updated