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\sandbox_pipeline@tmp\durable-2d7dd2f8\script.sh: 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?
[UPDATE]
Jenkins somehow can't create the SH
temporary file. Already checked the log, permissions, everything that came to my mind.
On Linux, BSD, and Mac OS (Unix-like) systems, the sh step is used to execute a shell command in a Pipeline. Jenkinsfile (Declarative Pipeline) pipeline { agent any stages { stage('Build') { steps { sh 'echo "Hello World"' sh ''' echo "Multiline shell steps works too" ls -lah ''' } } } }
you can execute shell in jenkins as a build step like this. echo "Hello World!" With previous action our server will not ask for password when we execute that command. If you need to execute a shell script in another server, then ssh is your best friend.
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.
bat
step instead of sh
.From Jenkins docs:
Windows-based systems should use the bat step for executing batch commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With