Hudson on Windows - 错误:java.io.IOException:无法运行程序“sh”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15135771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hudson on Windows - Error: java.io.IOException: Cannot run program "sh"
提问by Markus_DE_HH
I am trying to do continuous integration with Hudson and MSTest.
我正在尝试与 Hudson 和 MSTest 进行持续集成。
When I try to run this job I get the following error:
当我尝试运行此作业时,出现以下错误:
1 Warnung(en)
0 Fehler
Verstrichene Zeit 00:00:00.13
[workspace] $ sh -xe C:\Windows\TEMP\hudson4419897732634199534.sh
The system cannot find the file specified
FATAL: Befehlsausführung fehlgeschlagen
java.io.IOException: Cannot run program "sh" (in directory "C:\Users\Markus\.hudson\jobs\Test1 Unit TEst\workspace"): CreateProcess error=2, Das System kann die angegebene Datei nicht finden
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:187)
at hudson.Proc$LocalProc.<init>(Proc.java:157)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:649)
at hudson.Launcher$ProcStarter.start(Launcher.java:266)
at hudson.Launcher$ProcStarter.join(Launcher.java:273)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:79)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:54)
at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:34)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:646)
at hudson.model.Build$RunnerImpl.build(Build.java:181)
at hudson.model.Build$RunnerImpl.doRun(Build.java:136)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:434)
at hudson.model.Run.run(Run.java:1390)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:40)
at hudson.model.ResourceController.execute(ResourceController.java:81)
at hudson.model.Executor.run(Executor.java:137)
Caused by: java.io.IOException: CreateProcess error=2, Das System kann die angegebene Datei nicht finden
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 17 more
Processing tests results in file results.trx
FATAL: No MSTest TRX test report files were found. Configuration error?
[DEBUG] Skipping watched dependency update for build: Test1 Unit TEst #5 due to result: FAILURE
Finished: FAILURE
My Configuration looks like this:
我的配置如下所示:
Buildverfahren
Build a Visual Studio project or solution using MSBuild
MSBuild Version MS Build .NET 4
MSBuild Build File trunk\UnitTestWithNHibernate\UnitTestWithNHibernate.sln
Command Line Arguments /p:Configuration=Release
My Command Line looks like this:
我的命令行如下所示:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"
/runconfig: trunk\UnitTestWithNHibernate\UnitTest\LocalTestRun.testrunconfig /testcontainer: trunk\UnitTestWithNHibernate\UnitTest\bin\Debug\UnitTest.dll /resultsfile:results.trx
回答by funkybro
This happens if you have specified your Windows command as "Execute shell" rather than "Execute Windows batch command".
如果您将 Windows 命令指定为“执行 shell”而不是“执行 Windows 批处理命令”,则会发生这种情况。
回答by ajith
This is happens because Jenkins is not aware about the shell path.
In Manage Jenkins -> Configure System -> Shell, set the shell path as
这是因为 Jenkins 不知道 shell 路径。
在 Manage Jenkins -> Configure System -> Shell 中,将 shell 路径设置为
C:\Windows\system32\cmd.exe
C:\Windows\system32\cmd.exe
回答by Nate
In my case the builds worked using the "Execute shell" before doing a system reboot and migration and gave the Cannot run program "sh"
after. The issue was that the system path got shorter unexpectedly. It's not clear why, but the path lost C:\Program Files (x86)\Git\bin
and the version of Git I was using comes with sh.exe
.
在我的情况下,构建在执行系统重新启动和迁移之前使用“执行外壳”工作,并给出了Cannot run program "sh"
之后。问题是系统路径意外变短了。不清楚为什么,但是路径丢失C:\Program Files (x86)\Git\bin
了,我使用的 Git 版本带有sh.exe
.
Of course, you could just change all your "Execute shell" build steps to "Execute Windows batch command" in all your jobs as suggested by @funkybro. This doesn't solve your problem if you have a job that could run on either a Windows system or Linux and you have both systems for other reasons.
当然,您可以按照@funkybro 的建议,在所有作业中将所有“执行外壳”构建步骤更改为“执行 Windows 批处理命令”。如果您的作业可以在 Windows 系统或 Linux 上运行,并且由于其他原因同时拥有这两个系统,那么这并不能解决您的问题。
Or, you could change this setting to use cmd.exe
as suggested by @ajith: Manage Jenkins -> Configure System -> Shell -> Shell executable = C:\Windows\system32\cmd.exe
或者,您可以更改此设置以cmd.exe
按照@ajith 的建议使用:Manage Jenkins -> Configure System -> Shell -> Shell executable =C:\Windows\system32\cmd.exe
But, I like having linux commands and using something that more closely resembles Bash. It's my own preference but I thought this might also be helpful. To start from the beginning, I used Chocolatey NuGetto install Git. I also recommend GnuWin to give you some of the very helpful Unix commands.
但是,我喜欢使用 linux 命令并使用更类似于 Bash 的东西。这是我自己的偏好,但我认为这也可能有帮助。从头开始,我使用Chocolatey NuGet来安装 Git。我还推荐 GnuWin 为您提供一些非常有用的 Unix 命令。
- Install Chocolatey NuGet
- In CMD or PowerShell:
cinst gnuwin git
- 安装巧克力 NuGet
- 在 CMD 或 PowerShell 中:
cinst gnuwin git
Then you can fix this using the Windows UI by adding C:\Program Files (x86)\Git\bin\
to the system path.
然后,您可以使用 Windows UI 通过添加C:\Program Files (x86)\Git\bin\
到系统路径来修复此问题。
Or you can fix it in Jenkins global config: Manage Jenkins -> Configure System -> Shell -> Shell executable = C:\Program Files (x86)\Git\bin\sh.exe
或者您可以在 Jenkins 全局配置中修复它:Manage Jenkins -> Configure System -> Shell -> Shell executable = C:\Program Files (x86)\Git\bin\sh.exe
回答by Em Nguyen
The way to fix the problem was to put the value of C:\Windows\system32\cmd.exe
into the "Shell executable" configuration in Hudson System configuration.
解决问题的方法是将 的值C:\Windows\system32\cmd.exe
放入 Hudson 系统配置中的“Shell 可执行文件”配置中。
In build section of your job, you can put windows command to execute after compiling the project EX:
在您的工作的构建部分,您可以在编译项目 EX 后放置 windows 命令来执行:
copy target\pmd-rules-extensions-0.0.1-SNAPSHOT.jar D:\projects\sonar\sonar-3.4.1\extensions\rules\pmd\
回答by Ambitious
This issue will be resolved by trying this command to make the jenkins job run For me it work, just try to update this in manage jenkins -->configure system -->search for shell -->and in shell executable give the following command. It helps!!!
通过尝试此命令使 jenkins 作业运行来解决此问题对我来说它可以工作,只需尝试在管理 jenkins --> 配置系统 --> 搜索外壳 --> 并在外壳可执行文件中提供以下命令来解决此问题. 它有助于!!!
C:\Program Files\Git\bin\sh.exe
C:\Program Files\Git\bin\sh.exe