[英]Not able to include 'git' gem in ruby Gemfile
我是紅寶石的新手,並創建了一個使用Git gem的腳本。 ( require 'git'
)。 我必須對jenkins執行此腳本,並為其添加了Gemfile
和Gemfile.lock
,條目如下:
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
當嘗試使用以下命令通過jenkins執行腳本時:
#!/bin/bash -l
rvm use 1.9.3
bundle install --gemfile Gemfile --deployment
bundle exec ruby processMetadata.rb
請幫助我解決以下提到的錯誤:
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
看起來您是手工制作的Gemfile.lock
文件。 通常不需要使用此文件,因為該文件是由bundle
自動生成的。 它實質上包含捆綁程序為您下載的確切版本號。
捆綁軟件在部署模式( --deployment
)中運行時,將檢查兩個文件,並且如果它們之間存在任何不匹配,或者Gemfile.lock文件是否需要任何更新,則將拒絕運行。 這是作為完整性檢查來完成的,因為這些文件應在開發期間而不是在生產期間同步進行。
嘗試刪除Gemfile.lock
,然后重新開始。 由於您需要使用的版本號已經存在於您的Gemfile
,因此應該可以正確Gemfile.lock
而不出現任何問題。 同樣,首先不要在--deployment
模式下運行它,因為那樣不會生成Gemfile.lock
文件。
您從捆綁程序收到的錯誤消息中實際上記錄了所有這些步驟:
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.
請注意,之后生成的Gemfile.lock
文件仍然很重要(它包含您正在使用的確切版本),並且應成為存儲庫的一部分。
您可能還會遇到的另一個問題是,您仍在使用ruby 1.9,因此還必須像這樣修復Gemfile
的pg
gem版本:
source 'https://rubygems.org'
gem 'pg', '~> 0.18.4'
gem 'git', '~> 1.3'
生成的Gemfile.lock
將如下所示:
GEM
remote: https://rubygems.org/
specs:
git (1.3.0)
pg (0.18.4)
PLATFORMS
ruby
DEPENDENCIES
git (~> 1.3)
pg (~> 0.18.4)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.