我试图让 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 的方法)。