trusk
trusk

Reputation: 1703

macOS Jenkins uses system ruby instead of installed ruby

A client has jenkins setup on a macOS machine. It's doing iOS builds and uses bundler to install some gems. One gem recently started requiring a dependency which in turn requires ruby >= 2.1

Installing jwt 2.1.0
Gem::InstallError: jwt requires Ruby version >= 2.1.
An error occurred while installing jwt (2.1.0), and Bundler cannot continue.

For one, I've installed rvm and ruby 2.1.0 on the macOS machine

osxbuildserver:~ jenkins$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin14.0]

and for the ssh login user it shows up fine. The issue is that even tough Jenkins runs under the same jenkins user

root            15102     1 15102      0    0 Ss     ??    0:00.04 sshd: jenkins [priv] 
jenkins         15106 15102 15102      0    0 S      ??    0:00.03 sshd: jenkins@ttys000

it still uses the system ruby which is 2.0.0. In one of the builds I've added a shell script with ruby -v

[EnvInject] - Variables injected successfully.
[workspace] $ /bin/sh -xe     /var/folders/6v/xlw3p2pn47d2jl_jghf25dn00000gr/T/hudson73325394438439334.sh    
+ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

Calling

ssh jenkins@osxbuild "echo $PATH"

from my local machine, returns the incorrect path

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

but login in with the same user is fine

osxbuildserver:~ jenkins$ echo $PATH
/Users/jenkins/.rvm/gems/ruby-2.1.0/bin:/Users/jenkins/.rvm/gems/ruby-2.1.0@global/bin:/Users/jenkins/.rvm/rubies/ruby-2.1.0/bin.... etc

I've already tried the answer from here Jenkins using System Ruby - use rvm ruby? but it didn't help.

my .bash_profile contents

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
export ANDROID_HOME=/Users/jenkins/Library/Android/sdk
export ANDROID_SDK=$ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$JAVA_HOME
export TESSDATA_PREFIX=$HOME/tesseract-ocr

source ~/.profile
source $HOME/.rvm/scripts/rvm

Upvotes: 2

Views: 2517

Answers (2)

Avendi Sianipar
Avendi Sianipar

Reputation: 261

I messed up with this problem for a few days, finally its working well, thanks to the inspiration from @BlackRainbow

What Exactly I Do:

  1. Used rbenv to manage my Ruby environment
  2. Open terminal and execute echo $PATH
  3. Copy the result and paste to Jenkinsfile
  4. Re-try to build your pipeline
  5. Thats it, and its working well in my enviroment

Attachment:

Step 1-2 To Configure Ruby & Get Path Env -


Step 2-3 To Configure Jenkinsfile -


Step 4 Build Pipeline -

Upvotes: 0

BlackRainbow
BlackRainbow

Reputation: 1904

The question is quite old but probably somebody will use my solution. I copied everything that gave me echo $PATH. Then I opened Jenkin's configuration and found "Global properties". I added PATH and as a value I added value from terminal. jenkins environment set up

Upvotes: 6

Related Questions