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

ⅰ亾dé卋堺 提交于 2020-01-29 03:45:08

问题


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?


回答1:


I've worked it out. Jenkins will simply pick the first sh.exe in the path. Git Bash has an exe at C:\Program Files\Git\usr\bin, so if you add that to the beginning of your path it will be picked up by Jenkins.

You have to restart your slave's connection with Jenkins after making this change, otherwise the Path won't propagate. If you're using the Java Web Start, just close the java window and relaunch it.




回答2:


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:

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.



来源:https://stackoverflow.com/questions/35043665/change-windows-shell-in-jenkins-from-cygwin-to-git-bash-msys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!