What shell is used in Jenkins when calling the shell
command? I'm running Jenkins on a Linux machine.
5 Answers
From the help/question mark icon of the "Execute shell" section:
Runs a shell script (defaults to sh, but this is configurable) for building the project.
If you go to Manage Jenkins --> Configure System you will find an option (called "Shell executable") to set the name or absolute path to the shell that you want your shell scripts to use...
For my system without configuring this option... it uses bash!
-
-
I see default shell with a jenkins 2.7.4 on CentOS 7.1 is bash (sh on OS is bash), default shell with a jenkins 2.32.1 on Debian 8 docker container is dash (sh on OS is dash).– gaoitheJan 27, 2017 at 13:42
-
1There is a way to change default shell interpreter directly in the Jenkinsfile pipeline script: support.cloudbees.com/hc/en-us/articles/…– sgargelMar 8, 2019 at 11:09
-
Thank you! I was adding #!/bin/bash to the top of my Jenkins scripts so I could use BASH array syntax and that was causing subtle and incomprehensible errors in the build– AkronMar 23, 2019 at 4:26
Simply declare your shell on the first line of your script as you do in any shell script file:
#!/bin/bash
-
8This do not work. Shell used is always the default shell of the *nix user who starts the process.– JanfyApr 26, 2016 at 12:38
-
This works for me, using a recent version of Jenkins as of 2016/05. May 27, 2016 at 21:31
-
1
-
3
-
Jenkins by default looks for sh
in the PATH
environment variable, however the result (e.g. /bin/sh
) may point to different shells. For example, on Ubuntu 6.10 or later, /bin/sh
is a symlink to Dash.
So for the question "what shell is used in Jenkins ...", it depends. To avoid the uncertainty, you can: (take Bash as an example)
- Explicitly configure shell executable in Manage Jenkins > Configure System > Shell > Shell executable, e.g.,
/bin/bash
. (system-wide configuration) - Use shebang line to specify the interpreter should be used, e.g.,
#!/usr/bin/env bash
(specific to a job)
I tried printing the env by adding the following shell command to my Jenkins build.
env
The output showed that the SHELL was set to tcsh
for my instance.
-
8
You can set the default shell using Jenkins > Manage Jenkins > Configure System > Shell executable.
For jobs that use a shell different from the default, begin the Execute shell build step with a shebang, such as:
#!/usr/bin/tcsh -e -x
command1
command2
...
You can even use /usr/bin/env
to use, say, Python:
#!/usr/bin/env python3
Beware that a space is not allowed after the #!
:
#! /usr/bin/tcsh # Wrong
This will give the error,
java.io.IOException: Cannot run program ""
I tested the above on Jenkins 1.625.3