Jenkins Pipeline cannot execute SH command file in a Windows slave

后端 未结 2 1322
無奈伤痛
無奈伤痛 2021-01-12 16:25

I\'m executing this code:

node(\'my_windows_slave\') {
   sh \'ls\'
}

In my Windows slave I can properly execute sh command:

相关标签:
2条回答
  • 2021-01-12 16:54

    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.

    0 讨论(0)
  • 2021-01-12 16:56

    Use the bat step instead of sh.

    From Jenkins docs:

    Windows-based systems should use the bat step for executing batch commands.

    0 讨论(0)
提交回复
热议问题