Windows上的Hudson-错误:java.io.IOException:无法运行程序“ sh”

问题描述 投票:37回答:5

我正在尝试与Hudson和MSTest进行持续集成。

[当我尝试运行此作业时,出现以下错误:

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$1.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

我的配置如下:

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

我的命令行看起来像这样:

"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
windows jenkins continuous-integration hudson
5个回答
88
投票

如果您将Windows命令指定为“ Execute shell”而不是“ Execute Windows batch command”,则会发生这种情况。


35
投票

之所以会这样,是因为Jenkins不了解Shell路径。在Manage Jenkins-> Configure System-> Shell中,将Shell路径设置为

C:\ Windows \ system32 \ cmd.exe


9
投票

在我的情况下,构建是在执行系统重新引导和迁移之前使用“执行外壳”进行的,之后给出了Cannot run program "sh"。问题是系统路径意外缩短。尚不清楚原因,但路径丢失了C:\Program Files (x86)\Git\bin,而我使用的Git版本附带了sh.exe

当然,您可以按照@funkybro的建议,在所有作业中将所有“执行外壳”构建步骤更改为“执行Windows批处理命令”。如果您有可以在Windows系统或Linux上运行的作业,并且由于其他原因同时拥有这两个系统,则这不能解决您的问题。

或者,您可以按照@ajith的建议更改此设置以使用cmd.exe:管理Jenkins->配置系统-> Shell-> Shell可执行文件= C:\Windows\system32\cmd.exe

但是,我喜欢使用linux命令并使用更类似于Bash的东西。这是我自己的偏好,但我认为这可能也会有所帮助。从头开始,我使用Chocolatey NuGet安装Git。我还建议使用GnuWin为您提供一些非常有用的Unix命令。

然后您可以使用Windows UI通过将C:\Program Files (x86)\Git\bin\添加到系统路径来解决此问题。

或者您可以在Jenkins全局配置中修复它:管理Jenkins->配置系统-> Shell-> Shell可执行文件= C:\Program Files (x86)\Git\bin\sh.exe


2
投票

解决问题的方法是将C:\Windows\system32\cmd.exe的值放入Hudson System配置中的“ Shell可执行文件”配置中。

在工作的构建部分,您可以在编译项目后将Windows命令执行例如:

copy target\pmd-rules-extensions-0.0.1-SNAPSHOT.jar D:\projects\sonar\sonar-3.4.1\extensions\rules\pmd\

0
投票

通过尝试执行以下命令以使jenkins作业运行,可以解决此问题对我来说,它的工作原理是,只需尝试在manage jenkins->配置系统->搜索shell->中进行更新,然后在shell可执行文件中输入以下命令即可。它有帮助!!

C:\ Program Files \ Git \ bin \ sh.exe

© www.soinside.com 2019 - 2024. All rights reserved.