What shell does Jenkins use?
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!
Simply declare your shell on the first line of your script as you do in any shell script file:
#!/bin/bash
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.
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