I am new to ruby and created a script which is using Git gem. (require 'git'
).
I have to execute this script to jenkins and for which I have added a Gemfile
and Gemfile.lock
and the entries are as below:
Gemfile
source 'https://rubygems.org'
gem 'pg'
gem 'git', '~> 1.3'
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
pg (0.18.4)
git (1.3.0)
PLATFORMS
ruby
DEPENDENCIES
pg
git
When tried to execute the script via jenkins using below commands:
#!/bin/bash -l
rvm use 1.9.3
bundle install --gemfile Gemfile --deployment
bundle exec ruby processMetadata.rb
Please help me to solve the error which is mentioned below:
Using /usr/local/rvm/gems/ruby-1.9.3-p551
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
You have added to the Gemfile:
* git (~> 1.3)
You have deleted from the Gemfile:
* git
/usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler/definition.rb:181:in `rescue in specs': Your bundle is locked to git (1.3.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of git (1.3.0) has removed it. You'll need to update your bundle to a different version of git (1.3.0) that hasn't been removed in order to install. (Bundler::GemNotFound)
from /usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler/definition.rb:175:in `specs'
from /usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler/definition.rb:235:in `specs_for'
from /usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler/definition.rb:224:in `requested_specs'
from /usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler/runtime.rb:118:in `block in definition_method'
from /usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler/runtime.rb:19:in `setup'
from /usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler.rb:99:in `setup'
from /usr/local/rvm/gems/ruby-1.9.3-p551@global/gems/bundler-1.13.1/lib/bundler/setup.rb:20:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
Build step 'Execute shell' marked build as failure
It looks like you manually crafted the
Gemfile.lock
file. This is usually never needed, as that file is generated bybundle
automatically. It essentially contains the exact version numbers that bundler has downloaded for you.Bundle, when running in deployment mode (
--deployment
) will check both of your files, and will refuse to run, if there are any mismatches between them, or if the Gemfile.lock file would need any updates. This is done as a sanity check, as those files should be made in sync while development, and not during production.Try to remove
Gemfile.lock
, and start over. Since the version numbers you need to use are already present inside yourGemfile
, it should make a properGemfile.lock
without any issues. Also at first do not run it in--deployment
mode, as that one will not generate aGemfile.lock
file.All of these steps are actually noted in the error message you re receiving from bundler:
Note that the
Gemfile.lock
file that is generated afterwards is still important (it contains the exact versions you are using), and should be part of your repository.Also an additional problem you might encounter is that you are still using ruby 1.9, so you also have to fix the
pg
gem version inside yourGemfile
like so:the resulting
Gemfile.lock
will be something like this: