2014-02-12 59 views
1

我想在給定的RVM Ruby安裝上下文的Jenkins服務器上運行bundle install未在Jenkins Shell環境中加載RVM

當我通過SSH登錄這一切工作正常:

which bundle 
# /Users/me/.rvm/gems/[email protected]/bin/bundle 

ruby -v 
# ruby 2.1.0p0 ... 

但我通過詹金斯做到這一點,當我得到這個:

which bundle 
# /usr/bin/bundle 

因此,我增加source ~/.bash_profile我的腳本的頂部這應該加載RVM的上下文,但爲此我得到以下輸出和bundle的路徑仍然是錯誤的:

+ 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 

現在我該如何告訴Jenkins始終加載RVM環境。謝謝:)

回答

1

當我運行詹金斯一個shell腳本,我像做

#!/bin/bash 
echo '##################### BUNDLE/MIGRATION #####################' 
source ~/.bashrc 
rvm use [email protected] 
bundle install 
bundle exec rake db:schema:load RAILS_ENV=test 
bundle exec rake db:test:prepare 

我我.bashrc我行

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

我不知道這是否是最先進的,但它的工作原理:-)

+0

謝謝,我的情況下路徑不見了。那麼我會堅持這種做法。 – Besi

+0

#!/ bin/bash 在添加之後工作,謝謝 – AlekseiPetrovski

+0

在許多情況下,您還需要在'bundle install'調用之前使用'gem install bundler'安裝bundler。 –

2

試試這個:rvm 2.1 do which bundle

+0

+ 1,nice,thi的作品。如果詹金斯知道全球範圍內的RVM,那就太好了,但是這可以完成這項工作。 – Besi