Sourcing bash file before every "run" command?

config

#1

Hi, I was wondering if it’s possible to source a file before each of my - run: commands? It doesn’t appear to source either .bashrc or .profile. I’m using nvm in my main image and right now, I’d have to do something like this, which is a bit annoying:

- run: ". ~/.nvm/nvm.sh; nvm use 7"
- run: ". ~/.nvm/nvm.sh; npm install"

etc.


Sourcing bashrc before run on machine executor
#2

Yes, you can! Define BASH_ENV: ~/.bashrc as an environment variable and it will automatically source ~/.bashrc for you on each run.

environment:
  BASH_ENV: "~/.nvm/nvm.sh"

#3

Thanks! I ended up with:

environment:
  BASH_ENV: ".circleci/bash_env.sh"

And .circleci/bash_env.sh:

# for local builds using "circleci build"
# will be ignored on circleci since env.sh is gitignored
circleci_env_file=".circleci/env.sh"
[ -f "${circleci_env_file}" ] && source "${circleci_env_file}"

# nvm
source ~/.nvm/nvm.sh

#4

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