Jenkins Pipeline cannot execute SH command file in a Windows slave
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()
}
Attention
You still executing SH
commands in a CMD
, it means some %d
for example can break your SH
command.
Use the bat
step instead of sh
.
From Jenkins docs:
Windows-based systems should use the bat step for executing batch commands.