Jenkins使用错误版本的Ruby(rvm)

问题描述:

有下一种情况:

  • 使用詹金斯
  • 已安装具有不同ruby版本(2+)的rvm
  • 已安装 rvm插件

使用ruby版本ruby-2.3.0@global

现在关于问题.在每次詹金斯工作开始后,我可以看到下一个输出:

Now about problem. After each starting of jenkins job I can see next output:

Capturing environment variables produced by 'rvm use ruby-2.3.0@global'
$ bash -c export
[workspace] $ bash -c " source /usr/local/rvm/scripts/rvm && rvm use --install --create ruby-2.3.0@global && export > rvm.env"
Using /usr/local/rvm/gems/ruby-2.3.0 with gemset global
...

似乎一切都应该正常. 但实际上jenkins使用ruby-2.2.0,因为在日志下面,我发现了这一点:

And seems everything should works ok. But in fact jenkins use ruby-2.2.0 because below in log I found this:

+++ __path_to_ruby=/usr/local/rvm/rubies/ruby-2.2.0/bin/ruby
+++ [[ -z /usr/local/rvm/rubies/ruby-2.2.0/bin/ruby ]]
+++ [[ /usr/local/rvm/rubies/ruby-2.2.0/bin/ruby != \/\u\s\r\/\l\o\c\a\l\/\r\v\m* ]]
+++ [[ /usr/local/rvm/rubies/ruby-2.2.0/bin/ruby == \/\u\s\r\/\l\o\c\a\l\/\r\v\m\/\b\i\n\/\r\u\b\y ]]
+++ [[ /usr/local/rvm/rubies/ruby-2.2.0/bin/ruby == \/\u\s\r\/\l\o\c\a\l\/\r\v\m* ]]
+++ [[ -z /usr/local/rvm/gems/ruby-2.2.0 ]]
+++ [[ -z /usr/local/rvm/gems/ruby-2.2.0:/usr/local/rvm/gems/ruby-2.2.0@global ]]
...

下一个来自这里的问题:

And next problem which stems from here:

Gem::InstallError: activesupport requires Ruby version >= 2.2.2.

如果我在执行外壳"区域中键入ruby -v命令-那么在日志中我会看到

Also if I type ruby -v command in "Execute shell" area - then in log I see this

+ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]

我还尝试直接在执行外壳"中启动命令rvm use ruby-2.3.0.

I also tried to start command rvm use ruby-2.3.0 directly in "Execute shell".

我也将此添加到了/var/lib/jenkis/.bashrc:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

并尝试将$HOME/.rvm更改为/usr/local/rvm

但是每次结果都是一样的.詹金斯不使用ruby-2.3.0

But everytime result the same. Jenkins does not use ruby-2.3.0

请帮助我弄清楚我错过了什么?

Please help me figure out what did I miss?

我也遇到了这个问题.原来,如果您以root身份安装rvm,则会出现问题.我们必须完全卸载rvm并以jenkins用户身份重新安装,之后该插件才能正确加载rubies.

I ran into this problem too. It turned out that there is an issue if you install rvm as root. We had to fully uninstall rvm and reinstall as the jenkins user, after which the plugin correctly loaded rubies.

您可以通过列出Jenkins的$ HOME变量指向的目录的内容来检测此问题.如果没有.rvm目录,则可能需要重新安装.

You can detect this problem by listing the contents of the directory pointed by Jenkins's $HOME variable. If there is no .rvm directory then you may need to reinstall.