bash 如何默认为 Jenkins shell 执行登录 shell
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17122986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I default to a login shell for Jenkins shell execution
提问by Marc Seeger
I want to use rvm (or rbenv/chruby for that matter) to select different ruby versions from within my Jenkins jobs. By default, Jenkins will use /bin/sh, which on Ubuntu, is dash.
我想使用 rvm(或 rbenv/chruby)从我的 Jenkins 作业中选择不同的 ruby 版本。默认情况下,Jenkins 将使用 /bin/sh,它在 Ubuntu 上是破折号。
For this to change, I can add
为了改变这一点,我可以添加
#!/bin/bash -l
To the top of every single shell execute function everywhere. Seeing as that's a lot of annoying work, I'd like to be able to set that somewhere central.
到每个单独的shell 的顶部到处执行函数。看到这是很多烦人的工作,我希望能够将其设置在中心位置。
Using the "Shell executable" configuration setting, I can get it to run bash, adding parameters like '-l' however will fail with
使用“Shell 可执行文件”配置设置,我可以让它运行 bash,添加像“-l”这样的参数但是会失败
"/bin/bash -l" -xe /tmp/hudson5660076222778817826.sh FATAL: command execution failed java.io.IOException: Cannot run program "/bin/bash -l" (in directory "/home/jenkins/jobs/workspace/rvm-test"): error=2, No such file or directory
“/bin/bash -l” -xe /tmp/hudson5660076222778817826.sh 致命:命令执行失败 java.io.IOException:无法运行程序“/bin/bash -l”(在目录“/home/jenkins/jobs/workspace” /rvm-test"): error=2, 没有那个文件或目录
I tried using the rvm plugin for jenkins, but that doesn't even install on the current release version.
我尝试使用 jenkins 的 rvm 插件,但它甚至没有安装在当前的发布版本上。
Any ideas? :)
有任何想法吗?:)
回答by Mic92
You could work around by creating a wrapper around bash:
#!/bin/sh # for ex.: /usr/local/bin/login-bash exec /bin/bash -l "$@"If you want to use the default ruby just use the rvm-shell, which comes with rvm. Login as the jenkins user and type:
$ which rvm-shell /home/jenkins/.rvm/bin/rvm-shell
您可以通过围绕 bash 创建一个包装器来解决:
#!/bin/sh # for ex.: /usr/local/bin/login-bash exec /bin/bash -l "$@"如果您想使用默认的 ruby,只需使用 rvm 附带的 rvm-shell。以 jenkins 用户身份登录并输入:
$ which rvm-shell /home/jenkins/.rvm/bin/rvm-shell
to get the path of the rvm-shell. Use this path for the "Shell executable" option.
获取 rvm-shell 的路径。将此路径用于“Shell 可执行文件”选项。

