Referencing other variables in environment variables


Hi! I’m working on migrating from CircleCI 1 to 2 for one of our projects. The only problem I’m having now is that my environment variables which references other variables (CIRCLE_BRANCH in my case) isn’t outputed right.

For example, I have a variable named TEMP_VAR with value foobar/${CIRCLE_BRANCH}. Referencing this in my config, it outputs simply foobar/${CIRCLE_BRANCH} without replacing CIRCLE_BRANCH with the current branch name.

Reading from the Environment Variables settings page it says that “The values can be any bash expression and can reference other variables, such as setting M2_MAVEN to ${HOME}/.m2)”. So I can’t figure out what is wrong in my case?

Did anyone run in to this problem as they migrated, or know what I’m missing here?



I don’t use nested env vars, but it may have something to do with where you use the nested var; variable expansion does not (yet) work in all YAML keys. It works in run keys, but there’s some that don’t work. Where are you trying to expand your variable?


Thanks for replying @halfer. I’m currently attempting to use it within the run command as follows:

      - image: circleci/node:8-browsers
    working_directory: ~/project-dir
      - run:
          name: "Debug"
          command: echo $TEMP_VAR


Yep, it should work there. If you are stuck, try doing the creation of a nested env var in a previous run step.

Something like:

export M2_MAVEN=${HOME}/.m2


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