Env variable doesn't work

I’m declaring env variable in circle ci config but variable is not set. What I’m doing wrong?

version: 2
jobs:
  build:
    machine: true # Use a Linux VM instead of docker environment
    working_directory: ~/bone
    environment:
      NODE_ENV: production
    steps:
    - checkout
    - run:
        name: "Setup custom environment variables"
        command: |
          echo 'export NODE_ENV="production"'
    - run: echo ${NODE_ENV}
    - run: docker network create bone-net
    - run: docker-compose up -d
    - run: docker exec bone yarn install --no-cache
    - run:
        name: Test BONE integration db tests
        command: docker exec bone yarn db
        no_output_timeout: 30m

workflows:
  version: 2
  build_and_test:
    jobs:
      - build

Each run command gets a new shell, so variables set in one do not persist to another. One solution is to put the commands (setting a var and reading a var) in the same step.

If you want the items to be in different steps, then you can write the var contents to a temp file, and then read it from there in another step.

2 Likes

Thanks a lot!

1 Like

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