What shell does Jenkins use?

Jenkins

Jenkins Problem Overview


What shell is used in Jenkins when calling the shell command? I'm running Jenkins on a Linux machine.

Jenkins Solutions


Solution 1 - Jenkins

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!

Solution 2 - Jenkins

Simply declare your shell on the first line of your script as you do in any shell script file:

#!/bin/bash

Solution 3 - Jenkins

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)

  1. Explicitly configure shell executable in Manage Jenkins > Configure System > Shell > Shell executable, e.g., /bin/bash. (system-wide configuration)
  2. Use shebang line to specify the interpreter should be used, e.g., #!/usr/bin/env bash (specific to a job)

Solution 4 - Jenkins

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.

Solution 5 - Jenkins

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPablo JomerView Question on Stackoverflow
Solution 1 - Jenkinssdmythos_grView Answer on Stackoverflow
Solution 2 - JenkinsNico ToubView Answer on Stackoverflow
Solution 3 - JenkinsJeremy KaoView Answer on Stackoverflow
Solution 4 - JenkinsPablo JomerView Answer on Stackoverflow
Solution 5 - JenkinsJohn McGeheeView Answer on Stackoverflow