Load environment variable from .env in shell script

Hi :wave:

I am working on automating our deployment process. We are using terraform on AWS and we need to setup some environment variable.

Here is how we are currently loading all environment variables coming from .env (working on MacOS):

# load .env from root project directory
set -a # automatically export all variables
source ../.env
set +a

It looks like this is not working when we run this shell script on CircleCI. Here is our pipeline:

      - image: cimg/base:stable-20.04
      - checkout
      - populate_env
      - install_aws_cli
      - install_terraform
      - run: |
          # Applying terraform
          cd deploy

Note: populate_env command is just reading some env var from CircleCI context to insert them into .env.

The script that should load env var from .env is apply.sh.

Also, we need variable expansion like: CIRCLECI_CONTEXT_NAME=inapps-${PROJECT_NAME}.

Do you guys have any idea of why it is not working on cimg/base:stable-20.04 but fine on MacOS?
Thanks in advance,


Forcing script execution with bash (bash apply.sh) fixed the issue. I guess bash isn’t the default shell executor?

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