繁体   English   中英

无法在Ruby Gemfile中包含“ git”宝石

[英]Not able to include 'git' gem in ruby Gemfile

我是红宝石的新手,并创建了一个使用Git gem的脚本。 require 'git' )。 我必须对jenkins执行此脚本,并为其添加了GemfileGemfile.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,因此还必须像这样修复Gemfilepg 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM