Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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.

Using the "Shell executable" configuration setting, I can get it to run bash, adding parameters like '-l' however will fail with

"/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

I tried using the rvm plugin for jenkins, but that doesn't even install on the current release version.

Any ideas? :)

like image 332
Marc Seeger Avatar asked Jun 15 '13 11:06

Marc Seeger


People also ask

How do I default to bash?

Hold the Ctrl key, click your user account's name in the left pane, and select “Advanced Options.” Click the “Login Shell” dropdown box and select “/bin/bash” to use Bash as your default shell or “/bin/zsh” to use Zsh as your default shell. Click “OK” to save your changes.

How do I start a login shell?

A login shell is a shell given to a user upon login into their user account. This is initiated by using the -l or --login option, or placing a dash as the initial character of the command name, for example invoking bash as -bash.

How do you specify which shell is used when you login?

chsh command syntax-s {shell-name} : Specify your login shell name. You can obtained list of avialble shell from the /etc/shells file. User-name : It is optional, useful if you are a root user.


1 Answers

  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
    

to get the path of the rvm-shell. Use this path for the "Shell executable" option.

like image 91
Mic92 Avatar answered Nov 01 '22 07:11

Mic92