Jenkins 使用默认 ruby 但不是来自 RVM
Jenkins uses default ruby but not from RVM
我有 Jenkins 自动化服务器,它通过 ssh
与用户 snaggs
连接到我的机器。
我的机器有两个版本ruby
:
默认版本来自OS /System/Library/Frameworks/ ..... /usr/bin/ruby
ruby
v2.3.3 安装 RVM
在机器上,自动化 运行 是一些带有一些命令的 Perl 脚本。来自詹金斯的 whoami
给出 snaggs
当 Perl 脚本 运行s 命令 gem env
输出是:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14.1
- RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [universal.x86_64-darwin16]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-16
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/snaggs/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org"]
- REMOTE SOURCES:
- http://rubygems.org
但是,当我使用 ssh
进入同一台机器时,同一用户 snaggs
我安装了 ruby
版本 rvm
:
当我 运行 $ gem env
我得到输出:
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.8
- RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/snaggs/.rvm/gems/ruby-2.3.3
- USER INSTALLATION DIRECTORY: /Users/snaggs/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/snaggs/.rvm/rubies/ruby-2.3.3/bin/ruby
- EXECUTABLE DIRECTORY: /Users/snaggs/.rvm/gems/ruby-2.3.3/bin
- SPEC CACHE DIRECTORY: /Users/snaggs/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/snaggs/.rvm/rubies/ruby-2.3.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/snaggs/.rvm/gems/ruby-2.3.3
- /Users/snaggs/.rvm/gems/ruby-2.3.3@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org"]
- REMOTE SOURCES:
- http://rubygems.org
- SHELL PATH:
- /Users/snaggs/.rvm/gems/ruby-2.3.3/bin
- /Users/snaggs/.rvm/gems/ruby-2.3.3@global/bin
- /Users/snaggs/.rvm/rubies/ruby-2.3.3/bin
- /usr/local/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/snaggs/.rvm/bin
如何告诉 Jenkins 使用位于 /Users/snaggs/.rvm/gems/ruby-2.3.3
下的其他版本?
[编辑]
我不运行作为超级用户编写脚本
我在尝试配置 Java 版本时遇到了类似的问题。
看看Jenkins wiki:
When the SSH slaves plugin connects to a slave, it does not run an
interactive shell. Instead, it does the equivalent of your running "ssh
slavehost command..."
所以假设当您从 ssh 运行 gem env
时,您应该得到与 Jenkins 相同的结果:ssh snaggs@1.1.1.1 "gem env"
On machine the automation runs some Perl script with some commands.
您可以尝试创建一些与原始 .bash_profile
相同的自定义 .bash_profile_CUSTOM
您需要调用 .bash_profile_CUSTOM
因为 Jenkins 使用 own .bash_profile
默认情况下。运行 你的 perl 脚本如:
ssh snaggs@1.1.1.1 "source ~/.bash_profile_CUSTOM && perl some_perl_script.pl"
请记住,每次 Jenkins 连接到您的构建机器时,您都需要 绑定 bash_profile_CUSTOM
文件。所以从詹金斯命令可执行文件应该是这样的:
source ~/.bash_profile_CUSTOM && perl some_perl_script.pl
让我知道它是否有效或给你不同的输出
编辑:(25/12/2016)
如果您不想为 Jenkins 安装插件(例如 EnvInject Plugin 用于 Prefix Start Slave Command),您可以使用 bash 脚本包装 Perl 脚本,例如:
#!/bin/bash
source ~/. bash_profile_CUSTOM;
perl some_perl_script.pl;
因此 Perl 脚本将从您用 .bash_profile_CUSTOM
定义的配置文件开始。
我有 Jenkins 自动化服务器,它通过 ssh
与用户 snaggs
连接到我的机器。
我的机器有两个版本ruby
:
默认版本来自OS
/System/Library/Frameworks/ ..... /usr/bin/ruby
ruby
v2.3.3 安装 RVM在机器上,自动化 运行 是一些带有一些命令的 Perl 脚本。来自詹金斯的
whoami
给出snaggs
当 Perl 脚本 运行s 命令 gem env
输出是:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14.1
- RUBY VERSION: 2.0.0 (2015-12-16 patchlevel 648) [universal.x86_64-darwin16]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-16
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/snaggs/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org"]
- REMOTE SOURCES:
- http://rubygems.org
但是,当我使用 ssh
进入同一台机器时,同一用户 snaggs
我安装了 ruby
版本 rvm
:
当我 运行 $ gem env
我得到输出:
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.8
- RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/snaggs/.rvm/gems/ruby-2.3.3
- USER INSTALLATION DIRECTORY: /Users/snaggs/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/snaggs/.rvm/rubies/ruby-2.3.3/bin/ruby
- EXECUTABLE DIRECTORY: /Users/snaggs/.rvm/gems/ruby-2.3.3/bin
- SPEC CACHE DIRECTORY: /Users/snaggs/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/snaggs/.rvm/rubies/ruby-2.3.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/snaggs/.rvm/gems/ruby-2.3.3
- /Users/snaggs/.rvm/gems/ruby-2.3.3@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org"]
- REMOTE SOURCES:
- http://rubygems.org
- SHELL PATH:
- /Users/snaggs/.rvm/gems/ruby-2.3.3/bin
- /Users/snaggs/.rvm/gems/ruby-2.3.3@global/bin
- /Users/snaggs/.rvm/rubies/ruby-2.3.3/bin
- /usr/local/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/snaggs/.rvm/bin
如何告诉 Jenkins 使用位于 /Users/snaggs/.rvm/gems/ruby-2.3.3
下的其他版本?
[编辑]
我不运行作为超级用户编写脚本
我在尝试配置 Java 版本时遇到了类似的问题。
看看Jenkins wiki:
When the SSH slaves plugin connects to a slave, it does not run an interactive shell. Instead, it does the equivalent of your running "ssh slavehost command..."
所以假设当您从 ssh 运行 gem env
时,您应该得到与 Jenkins 相同的结果:ssh snaggs@1.1.1.1 "gem env"
On machine the automation runs some Perl script with some commands.
您可以尝试创建一些与原始 .bash_profile
相同的自定义 .bash_profile_CUSTOM
您需要调用 .bash_profile_CUSTOM
因为 Jenkins 使用 own .bash_profile
默认情况下。运行 你的 perl 脚本如:
ssh snaggs@1.1.1.1 "source ~/.bash_profile_CUSTOM && perl some_perl_script.pl"
请记住,每次 Jenkins 连接到您的构建机器时,您都需要 绑定 bash_profile_CUSTOM
文件。所以从詹金斯命令可执行文件应该是这样的:
source ~/.bash_profile_CUSTOM && perl some_perl_script.pl
让我知道它是否有效或给你不同的输出
编辑:(25/12/2016)
如果您不想为 Jenkins 安装插件(例如 EnvInject Plugin 用于 Prefix Start Slave Command),您可以使用 bash 脚本包装 Perl 脚本,例如:
#!/bin/bash
source ~/. bash_profile_CUSTOM;
perl some_perl_script.pl;
因此 Perl 脚本将从您用 .bash_profile_CUSTOM
定义的配置文件开始。