RVM未在Jenkins Shell环境中加载

时间:2014-02-12 11:26:31

标签: ruby-on-rails shell jenkins rvm bundler

我想在给定的RVM Ruby安装的上下文中在我的Jenkins服务器上运行bundle install

当我通过SSH登录时,一切正常:

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

ruby -v
# ruby 2.1.0p0 ...

但是当我通过Jenkins这样做时,我得到了这个:

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环境。谢谢:))

2 个答案:

答案 0 :(得分:2)

试试这个:rvm 2.1 do which bundle

答案 1 :(得分:2)

当我在Jenkins中运行shell脚本时,我会执行类似

的操作
#!/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

我的.bashrc我有行

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

我不知道这是否是最先进的,但它确实有效: - )