Jenkins - Rake插件找不到Rake

时间:2012-09-11 07:44:03

标签: ruby-on-rails jenkins rake jenkins-plugins

我在Jenkins工作中使用了几个Rake步骤(通过Rake插件),但它声称无法找到Rake:

+ bundle update
.................................
Using rake (0.9.2.2) 
.................................
[workspace] $ rake db:drop
FATAL: rake execution failed
java.io.IOException: Cannot run program "rake" (in directory "/var/lib/jenkins/jobs/myproject/workspace"): java.io.IOException: error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
    at hudson.Proc$LocalProc.<init>(Proc.java:244)
    at hudson.Proc$LocalProc.<init>(Proc.java:216)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:709)
    at hudson.Launcher$ProcStarter.start(Launcher.java:338)
    at hudson.Launcher$ProcStarter.join(Launcher.java:345)
    at hudson.plugins.rake.Rake.perform(Rake.java:141)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:717)
    at hudson.model.Build$BuildExecution.build(Build.java:199)
    at hudson.model.Build$BuildExecution.doRun(Build.java:160)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
    at hudson.model.Run.execute(Run.java:1502)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
    at java.lang.ProcessImpl.start(ProcessImpl.java:81)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:468)
    ... 15 more
Build step 'Invoke Rake' marked build as failure
Finished: FAILURE

如果我在Jenkins的配置中手动指定Ruby路径:

[workspace] $ rake db:drop
[31mERROR: Gem rake is not installed, run `gem install rake` first.(B[m
Build step 'Invoke Rake' marked build as failure
Finished: FAILURE

如果我在Jenkins中执行rake作为普通的shell命令,没有Rake插件:

+ rake db:drop
/var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.

当我执行“bundle exec rake db:drop”时发生相同但两次。

暂时在作业中包含两行:

rvm pkg install libyaml
rvm reinstall 1.9.3

无济于事。 (更新:这只是警告,不会影响任何事情,但非常烦人)。

我在〜/ .rvm目录下的Jenkins之外安装了另一个RVM + Ruby包,它运行正常。

2 个答案:

答案 0 :(得分:1)

不确定它是否对您有所帮助,但我遇到了类似的问题。问题是我安装Rake gem的Ruby路径不在Jenkins进程的路径中。

我正在使用的init.d脚本(/etc/init.d/jenkins)硬编码了PATH变量:

PATH=/bin:/usr/bin:/sbin:/usr/sbin

由于我正在使用ChefDK,因此我将嵌入式ChefDK Ruby添加到init.d脚本路径中:

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/chefdk/embedded/bin:/opt/chefdk/bin/

您可能需要根据Ruby的安装位置修改路径。希望这有助于某人。

答案 1 :(得分:0)

尝试Rake Plugin

根据我们的需要,RVM Plugin完成了这项工作,其余的就像bundle一样,我们放入了脚本/ shell构建步骤。