Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Windows shell in Jenkins (from Cygwin to Git Bash/msys)

I have a Windows 7 and a Windows Server 2012 slave with the Jenkins agent and Cygwin already set up. I want to avoid Cygwin and just use the Git Bash shell that comes with Git for Windows (I think it's called msysgit). So I renamed C:\cygwin64 to C:\cygwin64.bak, removed C:\cygwin64\bin from the path, and rebooted.

The Windows 2012 box now works fine, (Unix) shell scripts run, $OSTYPE = msys, and uname = MSYS_NT-6.3 (indicating that the Git Bash shell is running).

The Windows 7 box won't run anything, and gives the following error:

Building remotely on win7 in workspace C:\Users\Jenkins\workspace\TEST
[win7] $ sh -xe C:\Users\jenkins\AppData\Local\Temp\hudson5047939025129374618.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh" (in directory "C:\Users\Jenkins\workspace\TEST"): CreateProcess
error=2, The system cannot find the file specified.
       at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)

So my question is, how do I configure Jenkins to use C:\Program Files\Git\bin\sh.exe, or C:\Program Files\Git\usr\bin\bash.exe to run shell scripts?

like image 207
gib Avatar asked Jan 27 '16 17:01

gib


People also ask

Does git bash use Cygwin?

Git bash, and related tools in msysgit package, are pure Windows executables. That's why you cannot run Cygwin tools into Git bash, since these are not completely windows programs (they need the cygwin.

Does Jenkins use sh or 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.


2 Answers

Install git-bash

Ensure the Git\bin folder (i.e.: C:\Program Files\Git\bin) is in the global search path, in order for Jenkins to find sh.exe

to update path in windows use following command

setx path "%path%;C:\Program Files\Git\bin"

or have a look here https://www.windows-commandline.com/set-path-command-line/

to make nohup available for Jenkins

  • mklink "C:\Program Files\Git\bin\nohup.exe" "C:\Program Files\git\usr\bin\nohup.exe"

  • mklink "C:\Program Files\Git\bin\msys-2.0.dll" "C:\Program Files\git\usr\bin\msys-2.0.dll"

  • mklink "C:\Program Files\Git\bin\msys-iconv-2.dll" "C:\Program Files\git\usr\bin\msys-iconv-2.dll"

  • mklink "C:\Program Files\Git\bin\msys-intl-8.dll" "C:\Program Files\git\usr\bin\msys-intl-8.dll"

That's it now you can run shell commands

Have fun

like image 126
TARJU Avatar answered Sep 28 '22 00:09

TARJU


If you have only Windows agents and they all the have Git for Windows installed to the same location you can set the shell executable for all agents in the Jenkins System Configuration.

Go to Manage Jenkins > Configure System, scroll down to Shell and set the Shell executable to point to whatever shell you want to start with the Execute shell build step.

Here's an example how to set the shell which is installed with Git for Windows:

Jenkins shell configuration

Note: This won't work if you have a mixture of Windows and non-Windows agents (JENKINS-38211). It will cause similar issues if you have Windows agents where sh.exe is installed to different locations (such as a mixture of 32-bit and 64-bit Windows using the default install location for those platforms). Use this only when your environment contains only identically configured Windows nodes.

like image 39
apa64 Avatar answered Sep 28 '22 01:09

apa64