Question

Jenkins is running on an ubuntu machine. It has a special user jenkins which is used for executing the jobs.
RVM is installed and in an ssh shell on the server, logged in as the jenkins user, everything works fine.(If I set RVM to use ruby 1.9.3 ruby -vreturns 1.9.3 as version)
I use the RVM-plugin for Jenkins and have set it to use 1.9.3

Output by Jenkins for RVM: Capturing environment variables produced by 'rvm use 1.9.3' $ bash -c export
$ bash -c "test -f ~/.rvm/scripts/rvm"
$ bash -c "test -f /usr/local/rvm/scripts/rvm"
[workspace] $ bash -c " source /usr/local/rvm/scripts/rvm && rvm use --install --create 1.9.3 && export > rvm.env"
Using /usr/local/rvm/gems/ruby-1.9.3-p0


However if I later want to execute my script it uses ruby version 1.8.7.

Output for ruby version and environment:

  + which ruby  
  /usr/bin/ruby  
  + ruby -v  
  ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]  
  + rvm info  

 ruby-1.9.3-p0:  

  system:  
      uname:       "Linux h1332957.stratoserver.net 2.6.32-042stab078.27 #1 SMP Mon Jul 1 20:48:07 MSK 2013 i686 GNU/Linux"  
      bash:        "/bin/bash => GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)"  
      zsh:         " => not installed"  
   rvm:  
      version:    "rvm 1.9.2 by Wayne E. Seguin (wayneeseguin@gmail.com [https://rvm.beginrescueend.com/]"  
   ruby:  
      interpreter:  "ruby"  
      version:      "1.8.7"  
      date:         "2010-01-10"  
      platform:     "i486-linux"  
      patchlevel:   "2010-01-10 patchlevel 249"  
      full_version: "ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]"  
   homes:  
      gem:          "/usr/local/rvm/gems/ruby-1.9.3-p0"  
      ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p0"  
   binaries:  
      ruby:         "/usr/bin/ruby"  
      irb:          "/usr/bin/irb"  
      gem:          "/usr/bin/gem"  
      rake:         "/usr/bin/rake"  
   environment:  
      PATH:         "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/rvm/bin:/usr/local/rvm/bin"  
      GEM_HOME:     "/usr/local/rvm/gems/ruby-1.9.3-p0"  
      GEM_PATH:     "/usr/local/rvm/gems/ruby-1.9.3-p0:/usr/local/rvm/gems/ruby-1.9.3-p0@global"  
      MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-1.9.3-p0"  
      IRBRC:        "/usr/local/rvm/rubies/ruby-1.9.3-p0/.irbrc"  
      RUBYOPT:      ""  
      gemset:       ""  

Question:
How can I make Jenkins use ruby version 1.9.3 instead?

Was it helpful?

Solution

I solved the problem by sourcing rvm.
I updated my script to look like this:

 #!/bin/bash
 source "/usr/local/rvm/scripts/rvm"
 rvm use 1.9.3
 rvm info

Now the output by rvm info is correct.
Most important are the first and second line.


Output by rvm info:

 ruby-1.9.3-p0:

   system:
     uname:       "Linux h1332957.stratoserver.net 2.6.32-042stab078.27 #1 SMP Mon Jul 1 20:48:07 MSK 2013 i686 GNU/Linux"
     bash:        "/bin/bash => GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)"
     zsh:         " => not installed"

   rvm:
     version:      "rvm 1.9.2 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]"

   ruby:
     interpreter:  "ruby"
     version:      "1.9.3p0"
     date:         "2011-10-30"
     platform:     "i686-linux"
     patchlevel:   "2011-10-30 revision 33570"
     full_version: "ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]"

   homes:
     gem:          "/usr/local/rvm/gems/ruby-1.9.3-p0"
     ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p0"

   binaries:
     ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p0/bin/ruby"
     irb:          "/usr/local/rvm/rubies/ruby-1.9.3-p0/bin/irb"
     gem:          "/usr/local/rvm/rubies/ruby-1.9.3-p0/bin/gem"
     rake:         "/usr/local/rvm/gems/ruby-1.9.3-p0/bin/rake"

   environment:
     PATH:         "/usr/local/rvm/gems/ruby-1.9.3-p0/bin:/usr/local/rvm/gems/ruby-1.9.3-p0@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p0/bin:/usr/local/rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
     GEM_HOME:     "/usr/local/rvm/gems/ruby-1.9.3-p0"
     GEM_PATH:     "/usr/local/rvm/gems/ruby-1.9.3-p0:/usr/local/rvm/gems/ruby-1.9.3-p0@global"
     MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-1.9.3-p0"
     IRBRC:        "/usr/local/rvm/rubies/ruby-1.9.3-p0/.irbrc"
     RUBYOPT:      ""
     gemset:       ""

OTHER TIPS

Rvm creates a environment file on your workspace called "rvm.env". If you add:

source rvm.env

to all your shell scripts, you'll get the right environment without having to set up rvm manually.

Adding "rvm use x.x.x" didn't work for me. But it did produce a helpful error message:

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 an example.

My terminal emulator was already allowing login shell too.

Adding "--login" to the bash call got it to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top