无法在ruby Gemfile中包含'git'gem

时间:2016-12-22 07:05:10

标签: ruby gemfile gemfile.lock

我是ruby的新手并创建了一个使用Git gem的脚本。 (Gemfile)。 我必须对jenkins执行此脚本,并为其添加了Gemfile.lockGemfile 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 ,条目如下:

#!/bin/bash -l
rvm use 1.9.3
bundle install --gemfile Gemfile --deployment
bundle exec ruby processMetadata.rb

当尝试使用以下命令通过jenkins执行脚本时:

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

请帮我解决下面提到的错误:

strncmp(const char *a, reinterpret_cast<const char*>(unsigned char
 *b), size_t size);

1 个答案:

答案 0 :(得分:1)

看起来您手动制作了Gemfile.lock文件。这通常是不需要的,因为该文件是由bundle自动生成的。它基本上包含了bundler为您下载的确切版本号。

Bundle,在部署模式(--deployment)下运行时,将检查两个文件,如果它们之间存在任何不匹配,或者Gemfile.lock文件需要任何更新,则将拒绝运行。这是作为完整性检查完成的,因为这些文件应该在开发时同步,而不是在生产期间。

尝试删除Gemfile.lock,然后重新开始。由于您需要使用的版本号已经存在于Gemfile中,因此它应该正确Gemfile.lock而不会出现任何问题。另外,首先不要在--deployment模式下运行它,因为它不会生成Gemfile.lock文件。

所有这些步骤实际上都是在您从bundler收到的错误消息中注明的:

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,因此您还需要在pg内修复Gemfile 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)