What shell does Jenkins use?

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

#!/bin/bash

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!


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)

Tags:

Jenkins