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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:42:13  来源:igfitidea点击:

How can I default to a login shell for Jenkins shell execution

bashjenkinsrvmrbenv

提问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

  1. You could work around by creating a wrapper around bash:

    #!/bin/sh
    # for ex.: /usr/local/bin/login-bash
    exec /bin/bash -l "$@"
    
  2. 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
    
  1. 您可以通过围绕 bash 创建一个包装器来解决:

    #!/bin/sh
    # for ex.: /usr/local/bin/login-bash
    exec /bin/bash -l "$@"
    
  2. 如果您想使用默认的 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 可执行文件”选项。