0

我是 ruby​​ 新手,并创建了一个使用 Git gem 的脚本。( require 'git')。我必须向 jenkins 执行这个脚本,并为此添加了一个GemfileandGemfile.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
4

1 回答 1

1

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

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

尝试删除Gemfile.lock,然后重新开始。由于您需要使用的版本号已经存在于您GemfileGemfile.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,因此您还必须像这样修复pggem 版本Gemfile

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)
于 2016-12-22T07:09:37.240 回答