简体   繁体   English

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

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

I am new to ruby and created a script which is using Git gem. 我是红宝石的新手,并创建了一个使用Git gem的脚本。 ( require 'git' ). 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: 我必须对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

When tried to execute the script via jenkins using below commands: 当尝试使用以下命令通过jenkins执行脚本时:

#!/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. 看起来您是手工制作的Gemfile.lock文件。 This is usually never needed, as that file is generated by bundle automatically. 通常不需要使用此文件,因为该文件是由bundle自动生成的。 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. 捆绑软件在部署模式( --deployment )中运行时,将检查两个文件,并且如果它们之间存在任何不匹配,或者Gemfile.lock文件是否需要任何更新,则将拒绝运行。 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. 尝试删除Gemfile.lock ,然后重新开始。 Since the version numbers you need to use are already present inside your Gemfile , it should make a proper Gemfile.lock without any issues. 由于您需要使用的版本号已经存在于您的Gemfile ,因此应该可以正确Gemfile.lock而不出现任何问题。 Also at first do not run it in --deployment mode, as that one will not generate a Gemfile.lock file. 同样,首先不要在--deployment模式下运行它,因为那样不会生成Gemfile.lock文件。

All of these steps are actually noted in the error message you re receiving from 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.

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. 请注意,之后生成的Gemfile.lock文件仍然很重要(它包含您正在使用的确切版本),并且应成为存储库的一部分。

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 your Gemfile like so: 您可能还会遇到的另一个问题是,您仍在使用ruby 1.9,因此还必须像这样修复Gemfilepg gem版本:

source 'https://rubygems.org'
gem 'pg', '~> 0.18.4'
gem 'git', '~> 1.3'

the resulting Gemfile.lock will be something like this: 生成的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