What shell does Jenkins use?

后端 未结 5 1963
失恋的感觉
失恋的感觉 2020-12-09 07:05

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

相关标签:
5条回答
  • 2020-12-09 07:39

    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.

    0 讨论(0)
  • 2020-12-09 07:44

    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)
    0 讨论(0)
  • 2020-12-09 08:00

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

    #!/bin/bash
    
    0 讨论(0)
  • 2020-12-09 08:01

    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!

    0 讨论(0)
  • 2020-12-09 08:04

    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

    0 讨论(0)
提交回复
热议问题