TeamCity找不到rspec命令

时间:2014-05-29 19:32:57

标签: rspec continuous-integration rvm teamcity teamcity-8.0

我试图让TeamCity在我的rails应用程序上运行测试,但它没有看到rspec

rspec: command not found

我创建了一个"命令行"构建步骤包含以下内容:

rspec spec/

如果我在生成的目录中打开一个终端,在构建步骤失败后,我可以毫无问题地运行测试,这表明我在TeamCity环境中遇到了错误设置(与项目代码相对)。

我认为问题在于它无法切换到正确版本的ruby(我使用rvm进行ruby版本管理)。为了演示我到目前为止所完成的调试,我已经改变了我的命令行"构建步骤如下:

echo '#do rspec spec/'    
rspec spec/    
echo '#which rspec?'    
echo `which rspec`    
echo '#do bundle update'    
bundle update    
echo '#which ruby are we using?'    
echo `which ruby`    
echo '#which ruby do we want?'    
echo `more Gemfile | grep "ruby "`    
echo '#which bundle are we using?'    
echo `which bundle`    
echo '#available rubies?'    
echo `rvm list`    
echo '#switch to the right ruby: ruby-2.1.1'    
rvm use ruby-2.1.1    
echo '#try making rvm a function'    
source "$HOME/.rvm/scripts/rvm" &&     echo "rvm sourced."    
echo '#Try switching again'    
rvm use ruby-2.1.1    

结果输出为:

#do rspec spec/
/Users/tom/Desktop/TeamCity/buildAgent/temp/agentTmp/custom_script8352199801919263311: line 2: rspec: command not found
#which rspec?

#do bundle update
Your Ruby version is 2.1.2, but your Gemfile specified 2.1.1
#which ruby are we using?
/Users/tom/.rvm/rubies/ruby-2.1.2/bin/ruby
#which ruby do we want?
ruby "2.1.1"
#which bundle are we using?
/Users/tom/.rvm/gems/ruby-2.1.2@global/bin/bundle
#available rubies?
rvm rubies ruby-2.1.1 [ x86_64 ] =* ruby-2.1.2 [ x86_64 ] # => - current # =* - current && default # Gemfile Gemfile.lock Guardfile Procfile README.rdoc Rakefile app bin config config.ru db docs latest.dump lib log public scripts spec ssl vendor - default
#switch to the right ruby: ruby-2.1.1
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.

#try making rvm a function
rvm sourced.
#Try switching again
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.

Process exited with code 0

我已经阅读了数十个stackoverflow答案和博客,但仍然没有运气。我接下来可以尝试的任何想法? (我还没有找到让teamcity使用登录shell的方法。)

2 个答案:

答案 0 :(得分:2)

我找到了另一种(可能更好)的解决方案。

原来你可以添加一个" Build Feature"称为" Ruby环境配置器"它将Ruby解释器传递给所有构建步骤。

添加构建功能: http://confluence.jetbrains.com/display/TCD8/Adding+Build+Features

配置Ruby环境配置器: http://confluence.jetbrains.com/display/TCD8/Ruby+Environment+Configurator

答案 1 :(得分:1)

以下是三个选项:

  • 您可以使用Rake运行程序而不是命令行运行程序来回避问题。 Rake运行程序对RVM具有特定支持。设置" Ruby解释器" "模式"到RVM,您可以指定解释器和gemset。这是最简单的。

  • 您可以通过将Command Executable设置为您想要的Ruby解释器中的rspec可执行文件的完整路径(在〜/ .rvm中),并设置PATH,GEM_HOME,来使命令行运行器工作。 GEM_PATH和BUNDLE_PATH环境变量指向该解释器。这里的详细信息:https://rvm.io/integration/teamcity这将是更多的工作。

  • 您可以通过将命令可执行文件设置为' bash'来使命令行运行器工作。和命令参数' - login -c" rvm使用2.1.1; rspec spec"'。但是Haven没试过。