Jenkins Pipeline cannot execute SH command file in a Windows slave

纵然是瞬间 提交于 2019-12-01 03:24:44

问题


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.


回答1:


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.




回答2:


As said in Jenkins' docs, you should use the bat step instead of sh.



来源:https://stackoverflow.com/questions/41595897/jenkins-pipeline-cannot-execute-sh-command-file-in-a-windows-slave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!