Question

I want to run bundle install on my Jenkins server in the context of a given RVM Ruby Installation.

When I sign in via SSH it all works fine:

which bundle
# /Users/me/.rvm/gems/ruby-2.1.0@global/bin/bundle

ruby -v
# ruby 2.1.0p0 ...

But when I do this via Jenkins I get this:

which bundle
# /usr/bin/bundle

So I added source ~/.bash_profile to the top of my script which should load the RVM context but for this I get the following output and the path of bundle is still wrong:

+ source /Users/me/.bash_profile
++ [[ -s /Users/me/.profile ]]
++ source /Users/me/.profile
+++ PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Users/me/.rvm/bin
++ [[ -s /Users/me/.rvm/scripts/rvm ]]
++ source /Users/me/.rvm/scripts/rvm
+++ __rvm_has_opt posix
+++ [[ -n '' ]]
+++ [[ -n 3.2.51(1)-release ]]
+++ [[ :braceexpand:errexit:hashall:interactive-comments:posix:xtrace: =~ :posix: ]]
+++ return 0

+ which bundle
/usr/bin/bundle

Now how do I tell Jenkins to always load the RVM Environment. Thanks :)

Was it helpful?

Solution

When I run a shell script in Jenkins, I do something like

#!/bin/bash
echo '##################### BUNDLE/MIGRATION #####################'
source ~/.bashrc
rvm use 2.1@gemset
bundle install
bundle exec rake db:schema:load RAILS_ENV=test
bundle exec rake db:test:prepare

I my .bashrc I have the lines

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH=$PATH:$HOME/.rvm/bin

I do not know if this is the state of the art, but it works :-)

OTHER TIPS

Try this: rvm 2.1 do which bundle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top