Hudson on Windows - Error: java.io.IOException: Cannot run program "sh"
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
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\
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.
- Install Chocolatey NuGet
- In CMD or 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.
Or you can fix it in Jenkins global config: Manage Jenkins -> Configure System -> Shell -> Shell executable = C:\Program Files (x86)\Git\bin\sh.exe
This happens if you have specified your Windows command as "Execute shell" rather than "Execute Windows batch command".