在Jenkins上运行时找不到gem rspec-core(> = 0.a)(Gem :: GemNotFoundException) [英] can't find gem rspec-core (>= 0.a) (Gem::GemNotFoundException) when running on Jenkins
问题描述
我正在尝试在Jenkinsfile中运行ruby spec测试.
但是执行此代码时遇到了问题:
I am trying to run ruby spec tests in a Jenkinsfile.
However I have run into problems when executing this code:
sh 'rspec spec/unit/test_spec.rb'
这是错误:
/home/user/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems.rb:271:in 'find_spec_for_exe':找不到宝石耙(> = 0.a) (Gem :: GemNotFoundException)来自 /home/user/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems.rb:299:in 来自的"activate_bin_path" /home/user/.rvm/gems/ruby-2.4.0@global/bin/rake:23:in''来自 /home/user/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in eval' 来自/home/user/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in
/home/user/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems.rb:271:in 'find_spec_for_exe': can't find gem rake (>= 0.a) (Gem::GemNotFoundException) from /home/user/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems.rb:299:in 'activate_bin_path' from /home/user/.rvm/gems/ruby-2.4.0@global/bin/rake:23:in '' from /home/user/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in eval' from /home/user/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in ''
我正在EC2实例上运行Jenkins. gem rspec-core确实已安装,因为我在运行规格测试之前进行了捆绑安装.我还对实例本身(而不是Jenkins)运行了与实例完全相同的测试,并且它可以工作.
当我在Jenkins上运行gem which rspec
时,它给了我这个错误:
I am running Jenkins on an EC2 instance. The gem rspec-core is definitely installed, as I do a bundle install before running the spec test. I have also run the exact same test as the one on the instance itself instead of Jenkins and it works.
When I run gem which rspec
on Jenkins, it gives me this error:
错误:找不到ruby库文件或共享库rspec
ERROR: Can't find ruby library file or shared library rspec
但是当我在实例上运行它时,它会返回
/home/user/.rvm/gems/ruby-2.4.0@global/gems/rspec-3.6.0/lib/rspec.rb
But when I run it on the instance, it returns
/home/user/.rvm/gems/ruby-2.4.0@global/gems/rspec-3.6.0/lib/rspec.rb
两个都使用全局gemset. 可能是什么问题?
Both are using the global gemset. What could be the problem?
推荐答案
我设法通过
sh 'bundle exec rake spec:unit'
它使用rake文件而不是运行单独的测试本身,这更加清晰明了.
It uses the rake file instead of running the individual test itself, which is much more cleaner and clear.
这是rakefile的样子:
This is what the rakefile looks like:
namespace :spec do
RSpec::Core::RakeTask.new(:unit) do |t|`
t.pattern = 'spec/unit/**/*_spec.rb'
end
end
task default: ['spec:unit']
运行所有单元测试.
这篇关于在Jenkins上运行时找不到gem rspec-core(> = 0.a)(Gem :: GemNotFoundException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!