1
votes

I'm trying to get TeamCity to run the tests on my rails app, but it doesn't see rspec

rspec: command not found

I have created a "Command Line" build step containing the following:

rspec spec/

If I open a terminal at the generated directory, after the build step fails, I can run the tests without any problem, which suggests to me that it's something I'm doing wrong in my TeamCity environment setup (as opposed to the project code).

I believe the problem is that it is failing to switch to the correct version of ruby (I'm using rvm for my ruby version management). To demonstrate the debugging I've done so far, I have changed my "Command Line" build step to be the following:

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    

And the resulting output is:

#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

I've read dozens of stackoverflow answers and blogs, but still no luck. Any ideas what I can try next? (I haven't found a way to make teamcity use a login shell).

2

2 Answers

2
votes

I found another (possibly better) solution.

Turns out you can add a "Build Feature" called a "Ruby Environment Configurator" which passes a Ruby interpreter to all build steps.

Adding Build Features: http://confluence.jetbrains.com/display/TCD8/Adding+Build+Features

Configuring a Ruby Environment Configurator: http://confluence.jetbrains.com/display/TCD8/Ruby+Environment+Configurator

1
votes

Here are three options:

  • You can sidestep the problem by using a Rake runner instead of a Command Line runner. The Rake runner has specific support for RVM. Set the "Ruby interpreter" "Mode" to RVM and you can specify the interpreter and gemset. This is easiest.

  • You could get the command line runner to work by setting Command Executable to the full path to the rspec executable in the Ruby interpreter that you want (in your ~/.rvm), and setting the PATH, GEM_HOME, GEM_PATH and BUNDLE_PATH environment variables to point to that interpreter. Details here: https://rvm.io/integration/teamcity That would be more work.

  • You might get the command line runner to work by setting Command Executable to 'bash' and Command Parameters to '--login -c "rvm use 2.1.1; rspec spec"'. Haven't tried it though.