How to set ENV VARS for local builds using circleci 2.0


Hi, we rely on a couple of environment variables that we set on circleci to run our builds, so is there a way to set the environment variables for a circleci build run? I tried to set them as local variables, but didn’t look like it was being picked up.

Injecting custom environment variables when running locally via CircleCI CLI

We don’t yet have an ideal solution for that, but there is a workaround. Define which vars you want to export in a file within your repository (don’t commit it - just have it in the directory) and set BASH_ENV to that filename in your config.yml. The file will be automatically sourced on each command as long as BASH_ENV is correct.


With CircleCI 1, it used to be set with machine.environment.

    LOG_DIR: ${CIRCLE_ARTIFACTS}/testresults/

We use this quite a bit to set our own variables, so having no equivalent in v2 in inconvenient.
Could we move this in the “feature requests” category?
@rohra I found an example you provided here, pasting it below:

version: 2
      - image: circleci/ruby:2.3.3-node-browsers
      PROJECT_NAME: "myprojectname"
      PROJECT_DOMAIN: "project.domain"
      - run: echo $PROJECT_NAME
      - run: echo $PROJECT_DOMAIN

This does not seem to require using BASH_ENV?


That’s not evaluating env vars within others, that’s why you don’t need BASH_ENV. We already have an internal feature request open to address this, it’s just a lower priority than a lot of other issues.


You can vote in a feature request post to raise up this issue (hopefully ;-)).


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