如何在ubuntu上的jenkins中运行jruby

时间:2013-06-07 12:48:37

标签: ubuntu jenkins rvm jruby

我在jenkins中执行bash脚本时遇到问题。我检查了shell命令,输入如下:

rvm use jruby-1.7.4
export JRUBY_OPTS=--1.8
jruby -S cucumber

仅供参考:这些3个命令正是我在Jenkins外面发射黄瓜时在终端输入的内容。

当我执行这些命令时,这是我的输出

[workspace] $ /bin/sh -xe /home/nwssc/apache-tomcat-7.0.40/temp/hudson7305254619895710829.sh
+ rvm use jruby-1.7.4
RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.

+ export JRUBY_OPTS=--1.8
+ jruby -S cucumber
/home/nwssc/apache-tomcat-7.0.40/temp/hudson7305254619895710829.sh: 4: /home/nwssc/apache-tomcat-7.0.40/temp/hudson7305254619895710829.sh: jruby: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

所以我执行/ bin / bash --login作为我脚本的第一个命令,我仍然得到

[workspace] $ /bin/sh -xe /home/nwssc/apache-tomcat-7.0.40/temp/hudson7981126593924329573.sh
+ /bin/bash --login
+ rvm use jruby-1.7.4
RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.

+ export JRUBY_OPTS=--1.8
+ jruby -S cucumber
/home/nwssc/apache-tomcat-7.0.40/temp/hudson7981126593924329573.sh: 5: /home/nwssc/apache-tomcat-7.0.40/temp/hudson7981126593924329573.sh: jruby: not found
Build step 'Execute shell' marked build as failure

所以我尝试使用RVM插件并将其设置为使用jruby 1.7.4,这就是结果

Capturing environment variables produced by 'rvm use jruby-1.7.4'
$ bash -c export
$ bash -c "test -f ~/.rvm/scripts/rvm"
$ bash -c "test -f /usr/local/rvm/scripts/rvm"
[workspace] $ bash -c " source /usr/local/rvm/scripts/rvm && rvm use --install --create jruby-1.7.4 && export > rvm.env"
Using /usr/local/rvm/gems/jruby-1.7.4
[workspace] $ /bin/sh -xe /home/nwssc/apache-tomcat-7.0.40/temp/hudson661746741998327634.sh
+ export JRUBY_OPTS=--1.8
+ jruby -S cucumber
/home/nwssc/apache-tomcat-7.0.40/temp/hudson661746741998327634.sh: 3: /home/nwssc/apache-tomcat-7.0.40/temp/hudson661746741998327634.sh: jruby: not found
Build step 'Execute shell' marked build as failure

我做错了什么以及如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

重新加载bashrc或bash_profile以确保rvm已加载

/bin/bash --login
source ~/.bashrc
source ~/.bash_profile
rvm use jruby-1.7.4

我的bashrc有这个

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

bash_profile有这个

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*