21
Sep

java.io.IOException: Cannot run program “sh” (in directory “C:\xxx\path

For your Jenkins installation if you specify build step as “Execute Shell” with any shell commands (eg. ls or dir), following error is observed, if you have not specified your shell definition in Jenkins configuration:

 

java.io.IOException: Cannot run program "sh" (in directory "C:\Users\Path\.jenkins\jobs\SampleUnitTest..."): CreateProcess error=2, The system can't find the stated file

Solution:
Navigate to "Manage Jenkins" -> "Configure System" -> "Shell" and set the shell path to your cmd.exe as follow:

C:\Windows\system32\cmd.exe