简体   繁体   English

在 Jenkins 中更改 Windows shell(从 Cygwin 到 Git Bash/msys)

[英]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.我有一个 Windows 7 和一个 Windows Server 2012 slave,Jenkins 代理和 Cygwin 已经设置。 I want to avoid Cygwin and just use the Git Bash shell that comes with Git for Windows (I think it's called msysgit).我想避免使用 Cygwin,只使用 Git Git 附带的 Git Bash shell Windows(我认为它叫做 msysgit)。 So I renamed C:\cygwin64 to C:\cygwin64.bak , removed C:\cygwin64\bin from the path, and rebooted.所以我将C:\cygwin64重命名为 C C:\cygwin64.bak ,从路径中删除C:\cygwin64\bin ,然后重新启动。

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). Windows 2012 框现在工作正常,(Unix) shell 脚本运行, $OSTYPE = msysuname = MSYS_NT-6.3 (表明 Git Bash shell 正在运行)。

The Windows 7 box won't run anything, and gives the following error: Windows 7 框不会运行任何东西,并给出以下错误:

Building remotely on win7 in workspace C:\Users\Jenkins\workspace\TEST在工作区 C:\Users\Jenkins\workspace\TEST 中远程构建 win7
[win7] $ sh -xe C:\Users\jenkins\AppData\Local\Temp\hudson5047939025129374618.sh [win7] $ sh -xe C:\Users\jenkins\AppData\Local\Temp\hudson5047939025129374618.sh
The system cannot find the file specified该系统找不到指定的文件
FATAL: command execution failed FATAL:命令执行失败
java.io.IOException: Cannot run program "sh" (in directory "C:\Users\Jenkins\workspace\TEST"): CreateProcess java.io.IOException:无法运行程序“sh”(在目录“C:\Users\Jenkins\workspace\TEST”中):CreateProcess
error=2, The system cannot find the file specified. error=2, 系统找不到指定的文件。
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)在 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?所以我的问题是,如何配置 Jenkins 以使用C:\Program Files\Git\bin\sh.exeC:\Program Files\Git\usr\bin\bash.exe来运行 shell 脚本?

I've worked it out.我已经解决了。 Jenkins will simply pick the first sh.exe in the path. Jenkins 将简单地选择路径中的第一个 sh.exe。 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. Git Bash 在C:\\Program Files\\Git\\usr\\bin有一个 exe,所以如果你把它添加到你的路径的开头,Jenkins 就会选择它。

You have to restart your slave's connection with Jenkins after making this change, otherwise the Path won't propagate.进行此更改后,您必须重新启动奴隶与 Jenkins 的连接,否则路径将不会传播。 If you're using the Java Web Start, just close the java window and relaunch it.如果您使用的是 Java Web Start,只需关闭 Java 窗口并重新启动它。

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.如果您只有 Windows 代理,并且它们都将适用于 Windows 的 Git 安装到同一位置,您可以在 Jenkins 系统配置中为所有代理设置 shell 可执行文件。

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.转到Manage Jenkins > Configure System ,向下滚动到Shell并将Shell 可执行文件设置为指向您想要从执行 shell构建步骤开始的任何 shell。

Here's an example how to set the shell which is installed with Git for Windows:下面是一个如何设置与 Git for Windows 一起安装的 shell 的示例:

詹金斯外壳配置

Note: This won't work if you have a mixture of Windows and non-Windows agents ( JENKINS-38211 ).注意:如果您同时使用 Windows 和非 Windows 代理 ( 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).如果您有将sh.exe安装到不同位置的 Windows 代理(例如使用这些平台的默认安装位置的 32 位和 64 位 Windows 的混合),则会导致类似的问题。 Use this only when your environment contains only identically configured Windows nodes.仅当您的环境仅包含相同配置的 Windows 节点时才使用此选项。

Install git-bash安装 git-bash

Ensure the Git\\bin folder (ie: C:\\Program Files\\Git\\bin) is in the global search path, in order for Jenkins to find sh.exe确保 Git\\bin 文件夹(即:C:\\Program Files\\Git\\bin)在全局搜索路径中,以便 Jenkins 找到 sh.exe

to update path in windows use following command使用以下命令更新 Windows 中的路径

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

or have a look here https://www.windows-commandline.com/set-path-command-line/或在这里查看https://www.windows-commandline.com/set-path-command-line/

to make nohup available for Jenkins为 Jenkins 提供 nohup

  • mklink "C:\\Program Files\\Git\\bin\\nohup.exe" "C:\\Program Files\\git\\usr\\bin\\nohup.exe" 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-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-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" 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就是这样,您现在可以运行 shell 命令了

Have fun玩得开心

on the node agent configuration: check the Tool Locations, add the home path of git, for eg C:\Program Files\Git\cmd\git.exe and save reconnect the client.it will work在节点代理配置上:检查工具位置,添加 git 的主路径,例如 C:\Program Files\Git\cmd\git.exe 并保存重新连接客户端。它会工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM