RVM not loaded in Jenkins Script Environment
Nov 13, 2020
I wanted to run bundle install
on my Jenkins project script in the context of a given RVM Ruby Installation. But Jenkins wasn’t able to load/locate installed RVM. After digging into it, I did something like
#!/bin/bash
echo '##################### BUNDLE/MIGRATION #####################'
source ~/.bashrc
rvm use 2.6.5@gemset
bundle install
bundle exec rake db:schema:load RAILS_ENV=test
bundle exec rake db:test:prepare
In my .bashrc
I have the lines
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH=$PATH:$HOME/.rvm/bin
It should run now. But in case you’re still facing issue, do this.
#!/bin/bash -l
In the manual it says -l
"makes bash act as if it had been invoked as a login shell". So it worked for OP in the local machine so after adding it makes it works in jenkins also.
After these changes, it ran smoothly :)