Fatal error with Execute shell in project

Hey,
I have a problem:
When I create a project and click on “Build” and select Execute shell and build the project-
I got an error in the console output:

Started by user Rachel Cohen
Running as SYSTEM
Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\test_again
[test_again] $ sh -xe C:\WINDOWS\TEMP\jenkins1793137690508028130.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
Caused: java.io.IOException: Cannot run program "sh" (in directory "C:\ProgramData\Jenkins\.jenkins\workspace\test_again"): CreateProcess error=2, The system cannot find the file specified
	at java.lang.ProcessBuilder.start(Unknown Source)
	at hudson.Proc$LocalProc.<init>(Proc.java:254)
	at hudson.Proc$LocalProc.<init>(Proc.java:223)
	at hudson.Launcher$LocalLauncher.launch(Launcher.java:997)
	at hudson.Launcher$ProcStarter.start(Launcher.java:509)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:144)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:92)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:814)
	at hudson.model.Build$BuildExecution.build(Build.java:199)
	at hudson.model.Build$BuildExecution.doRun(Build.java:164)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522)
	at hudson.model.Run.execute(Run.java:1896)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
	at hudson.model.ResourceController.execute(ResourceController.java:101)
	at hudson.model.Executor.run(Executor.java:442)
Build step 'Execute shell' marked build as failure
Finished: FAILURE

The system cannot find the file specified
FATAL: command execution failed

If anyone knows what the problem is- it’ll help me a lot
thank you!
Rachel

That looks like you’re trying to run a ‘shell’ step on a windows node, which is unlikely to succeed, unless you have a specific shell executable installed there (in which case, it needs to be in the %PATH% of the node.

For windows nodes, you’d generally be looking at running either ‘bat’ or powershell steps for scripts.

Tony

1 Like

Thank you - It was help me a lot!

It happens because Jenkins is not aware about the shell path.
In my case the solution was:
In Manage Jenkins → Configure System → Shell, set the shell path as

C:\Windows\system32\cmd.exe

After doing this change, it works for me.
Hope it helps!

5 Likes

Thank you - this is very helpful :slight_smile:

Right, it works for me as well.

@lenemapse it worked for me. thank you lenemapse

it worked fine.Thanks!

Changing Execute shell to use the Windows command processor seems counter-intuitive to me. Wouldn’t it be better to use the “Execute batch command” step instead of “Execute shell”? The “Execute shell” step is generally used for programs that are POSIX compatible shells.

1 Like

Hi if you use in jenkin in window platfrom then use on below

// To run Maven on a Windows agent, use
bat “mvn -Dmaven.test.failure.ignore=true clean package”

This worked for me. I was skeptical about adding the SSH plugin due to issues relating to ‘CSRF vulnerability and missing permission checks in SSH Plugin allow capturing credentials’ and ‘Missing permission check in SSH Plugin allows enumerating credentials IDs’

I agree that it is wise to be skeptical about adding the ssh plugin due to known security vulnerabilities (SECURITY-2093 and SECURITY-2315).

As far as I know, there is nothing in the ssh plugin that will allow a shell step (“sh”) to run on Windows computers. I’m surprised that installing the ssh plugin made any change to how Pipeline steps execute on Windows agents.

Windows agents almost always use “bat” and “powershell” steps to perform their operations. Some users may have found ways to configure their Windows computers to also include a program that is compatible with “sh” and runs on Windows, but that is not the typical way that Windows agents are used.

1 Like

Thank you so much. Your comments was very useful