Hudson on Windows - Error: java.io.IOException: Cannot run program "sh"
Asked Answered
C

6

42

I am trying to do continuous integration with Hudson and 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$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

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
Connolly answered 28/2, 2013 at 12:39 Comment(2)
Found the Problem. Had to specify the shell to C\windows\system32\cmd.exeConnolly
Please answer your own question, so it can help others in the future, and so people don't read your whole question just to find out it's already solved.Stheno
A
107

This happens if you have specified your Windows command as "Execute shell" rather than "Execute Windows batch command".

Angloindian answered 28/8, 2013 at 9:53 Comment(0)
T
40

This happens because Jenkins is not aware about the shell path.
In Manage Jenkins -> Configure System -> Shell, set the shell path as

C:\Windows\system32\cmd.exe

Tref answered 13/5, 2014 at 14:38 Comment(4)
shouldn't it figure that out from PATH?Ave
Hello, I have windows as well as linux machines as slaves. If i set path of cmd.exe then it will stop working for linux machinesHydrosol
@ajith: I set this path on windows machine and in job executing shell command as echo 'HelloWorld' but not printingConfirmation
I got same result as @Swift, build success but I think it did not execute the commandZoologist
M
12

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.

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.

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

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 NuGet to install Git. I also recommend GnuWin to give you some of the very helpful Unix commands.

Then you can fix this using the Windows UI by adding C:\Program Files (x86)\Git\bin\ to the system path.

Or you can fix it in Jenkins global config: Manage Jenkins -> Configure System -> Shell -> Shell executable = C:\Program Files (x86)\Git\bin\sh.exe

Marysa answered 15/7, 2014 at 15:15 Comment(4)
Thanks @Nate. I had the same issue. The problem was that my git install only added \Git\cmd\ and not \Git\bin..Homologize
I also had to reset the connection with the node to make Jenkins reload the PATH.Yarmouth
If I specify the shell executable on the global Jenkins' config, even my Linux and OSX slave tries to use it, which results in them both failing?! Is there a way of just specifying the shell executable path for my Windows' slave?Theologize
That's an excellent question but unfortunately I don't know the answer and I don't have Jenkins set up anymore to experiment. I suggest you try to look for slave-specific settings or look for other solutions. Sorry I can't help more.Marysa
E
4

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!!!

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

Every answered 2/5, 2020 at 16:12 Comment(0)
T
2

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.

In build section of your job, you can put windows command to execute after compiling the project EX:

copy target\pmd-rules-extensions-0.0.1-SNAPSHOT.jar D:\projects\sonar\sonar-3.4.1\extensions\rules\pmd\
Tung answered 24/10, 2014 at 7:57 Comment(0)
D
0

Just use the "windows batch command" and enter the windows commands as you would want to type them on the command line.

Donner answered 6/10, 2020 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.