TeamCity找不到rspec命令

TeamCity找不到rspec命令,rspec,continuous-integration,rvm,teamcity,teamcity-8.0,Rspec,Continuous Integration,Rvm,Teamcity,Teamcity 8.0,我试图让TeamCity在我的rails应用程序上运行测试,但它没有看到rspec rspec: command not found 我创建了一个“命令行”构建步骤,其中包含以下内容: rspec spec/ echo '#do rspec spec/' rspec spec/ echo '#which rspec?' echo `which rspec` echo '#do bundle update' bundle update echo

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

rspec: command not found
我创建了一个“命令行”构建步骤,其中包含以下内容:

rspec spec/
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    
如果我在生成的目录中打开一个终端,在构建步骤失败后,我可以毫无问题地运行测试,这向我表明这是我在TeamCity环境设置中做错的事情(与项目代码相反)

我认为问题在于它无法切换到正确的ruby版本(我正在使用rvm进行ruby版本管理)。为了演示我迄今为止所做的调试,我将“命令行”构建步骤更改为:

rspec spec/
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

我已经读了几十个答案和博客,但仍然没有运气。你知道我下一步可以试试什么吗?(我还没有找到让teamcity使用登录shell的方法)。

这里有三个选项:

  • 您可以通过使用Rake运行程序而不是命令行运行程序来回避这个问题。耙式转轮对RVM有特定的支持。将“Ruby解释器”模式设置为RVM,您可以指定解释器和gemset。这是最简单的

  • 您可以通过将command Executable设置为您想要的Ruby解释器(在~/.rvm中)中rspec可执行文件的完整路径,并将path、GEM_HOME、GEM_path和BUNDLE_path环境变量设置为指向该解释器,从而使命令行运行程序正常工作。这里的细节:这将是更多的工作

  • 您可以通过将command Executable设置为'bash'并将command参数设置为'--login-c“rvm use 2.1.1;rspec spec”'来让命令行运行程序工作。但我还没试过

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

事实证明,您可以添加一个名为“Ruby环境配置器”的“构建特性”,它将Ruby解释器传递给所有构建步骤

添加生成功能:

配置Ruby环境配置器: