Search code examples
rubyjenkinsrbenv

Jenkins, rbenv, bundler - When using Jenkins and rbenv, how does the rbenv plugin preinstall bundler, and why isn't it in my case?


I'm setting up a CI environment on OSX using Jenkins and Appium's Ruby library.

I'm using a rake task to launch my test suite in RSpec.

Using a similar configuration, I was able to run the tests with Jenkins on another machine. I'm now using rbenv (and the rbenv plugin) and having some issues.

Here's what I get when I try to run the job:

$ bash -c "[ -d \$HOME/.rbenv-jenkins ]"
$ bash -c "[ -d \$HOME/.rbenv-jenkins/plugins/ruby-build ]"
$ bash -c "cd /Users/Shared/Jenkins/Home/workspace/Tests && env  RBENV_ROOT\=\$HOME/.rbenv-jenkins RBENV_VERSION\=2.2.5 CONFIGURE_OPTS\= RUBY_CONFIGURE_OPTS\= \$HOME/.rbenv-jenkins/bin/rbenv local 2>/dev/null || true"
Use local Ruby version 2.2.5.
$ bash -c "mkdir \$HOME/.rbenv-jenkins/.lock"
$ bash -c "env RBENV_ROOT\=\$HOME/.rbenv-jenkins RBENV_VERSION\=2.2.5 CONFIGURE_OPTS\= RUBY_CONFIGURE_OPTS\= \$HOME/.rbenv-jenkins/bin/rbenv versions --bare"
$ bash -c "env RBENV_ROOT\=\$HOME/.rbenv-jenkins RBENV_VERSION\=2.2.5 CONFIGURE_OPTS\= RUBY_CONFIGURE_OPTS\= \$HOME/.rbenv-jenkins/bin/rbenv rehash"
$ bash -c "env RBENV_ROOT\=\$HOME/.rbenv-jenkins RBENV_VERSION\=2.2.5 CONFIGURE_OPTS\= RUBY_CONFIGURE_OPTS\= \$HOME/.rbenv-jenkins/bin/rbenv exec gem list"
$ bash -c "env RBENV_ROOT\=\$HOME/.rbenv-jenkins RBENV_VERSION\=2.2.5 CONFIGURE_OPTS\= RUBY_CONFIGURE_OPTS\= \$HOME/.rbenv-jenkins/bin/rbenv rehash"
$ bash -c "rm -rf \$HOME/.rbenv-jenkins/.lock"
[Tests] $ bundle exec rake ios
FATAL: rake execution failed
java.io.IOException: Cannot run program "bundle" (in directory "/Users/Shared/Jenkins/Home/workspace/Tests"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:240)
at hudson.Proc$LocalProc.<init>(Proc.java:212)

etc.

It seems like there is an issue with bundler's exec not being where it is supposed to be.

I've tried adding export PATH="$HOME/.rbenv-jenkins/bin:$PATH" to the path in a few ways, but it seems like it doesn't make a difference - when it's a shell step I see it run, but I get no change.

I have preinstall rake and bundler enabled with my rbenv plugin, but I don't see them getting installed - I'm not sure why.

I am able to run tests via rspec, rake and bundle exec rake when I'm logged in to the Jenkins user.

Any idea what's not doing what it's supposed to be? Let me know if there are any missing details, and thank you!

edit:

When I add gem install bundle and gem install rake shell commands, I get the following:

+ gem install bundler
Successfully installed bundler-1.13.2
Parsing documentation for bundler-1.13.2
Done installing documentation for bundler after 4 seconds
1 gem installed
+ gem install rake
ERROR:  Error installing rake:
    "rake" from rake conflicts with /Users/Shared/Jenkins/.rbenv-jenkins/versions/2.2.5/bin/rake
Build step 'Execute shell' marked build as failure
Finished: FAILURE

My pre-install gems are rake,bundler - but it seems like only rake gets pre-installed correctly.

Running the job without installing rake (and with an rbenv rehash following the bundler install), I get the same error.


Solution

  • In this case, it turned out to be an error with gem dependencies - a bad nokogiri installation when all was said and done.

    I was able to reveal the error message that got me hunting by running bundle exec rake ios (my test task) as a shell command rather than as a rake task via the plugin.

    From there, I got an error about a bad version and after trying some gemfile tweaks (and nuking my Gemfile.lock), I ran bundle install as a shell line and noticed the nokogiri installation failing in familiar ways (due to some Xcode version juggling that I suspect is fairly idiosyncratic).

    So, if you're lost and looking for guidance in a similar spot, try running the task as a shell line so you get more verbose errors.