Search code examples
ruby-on-railsrubyjenkinscontinuous-integrationcapistrano

Setting up Jenkins in Ruby on Rails Environment


I am trying to setup Jenkins to build then deploy my rails application but my builds keep failing. It is because Jenkins is looking at the wrong version of Ruby and not using RVM. Here is the build fail log:

/tmp/hudson3481773306458146820.sh: line 4: rvm: command not found
/tmp/hudson3481773306458146820.sh: line 5: rvm: command not found
/tmp/hudson3481773306458146820.sh: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
/tmp/hudson3481773306458146820.sh: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
/tmp/hudson3481773306458146820.sh: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
/tmp/hudson3481773306458146820.sh: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
Build step 'Execute shell' marked build as failure
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE

Here is my build script:

#!/bin/bash
source /home/web/.bashrc
rvm use 2.2.3
rvm info
bundle install
bundle exec rake db:schema:load RAILS_ENV=test
bundle exec rake db:test:prepare
bundle exec rspec spec --order random --fail-fast

I am very lost on what to do, I've even tried to specify the ruby version in build script but it cannot find rvm.

Here is my .bashrc

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

Here is the output of rvm list:

web@localhost:~$ rvm list

rvm rubies

   ruby-2.1.5 [ x86_64 ]
=* ruby-2.2.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

ruby -v

ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]

Any idea what is going wrong?


Solution

  • You have two options to solve this, I think:

    • Install RVM for the jenkins user, just as you would for a developer. Then your build script will understand rvm.

    • Install the rvm plugin. (I had to install the LTS version of Jenkins before this would work for me.) Then you can take the RVM part out of the build script and make it an action.

    I'm pretty certain that either one of these will fix the above problem. You shouldn't need to do both.

    (Disclaimer: New to Jenkins myself.)