Jenkins Pipeline Can not Run the SH Command File in a Windows Slave


I'm executing this code:

node('my_windows_slave') {
   sh 'ls'

In my Windows slave I can properly execute sh command:

But the pipeline script can't run the .sh file:

[Pipeline] sh
[D:\workspace\sandbox_pipeline] Running shell script
sh: D:\workspace\san[email protected]\durable-2d7dd2f8\ command not found

What I could notice is that this .sh file is not even created, once I tried with bat and worked fined.

Any clue what could be the problem?


Jenkins somehow can't create the SH temporary file. Already checked the log, permissions, everything that came to my mind.

I will leave my workaround as an answer for while before approve it once I'm still not 100% sure about the root cause and might someone else show up with a elegant solution...

def shell(command) {
    return bat(returnStdout: true, script: "sh -x -c \"${command}\"").trim()


You still executing SH commands in a CMD, it means some %d for example can break your SH command.