Hudson on Windows - Error: java.io.IOException: Cannot run program "sh" Hudson on Windows - Error: java.io.IOException: Cannot run program "sh" windows windows

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


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


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


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