FWIW, I made a simple function in my Jenkins pipeline shared library (see (1) or (2)) that I often use that is mostly cross compatible on windows/Linux.
It calls sh or bat dependeing on the OS, as long as the passed command is compatible with both.
But that is the case for most maven or git commands.
With this utility, my pipeline is fully compatible with both OS and each project can force it's execution on Linux or Windows, it works.
Here is the file jenkins-shared-libraries/vars/batOrSh.groovy:
// Simple utility whose goal is to have a common utility in Jenkins pipeline or script running both on windows or Linux
def call(String command) {
if (isUnix()) {
sh command
} else {
bat command
}
}
def call(Map args) {
if (isUnix()) {
sh args
} else {
bat args
}
}
/** Sometimes we have to use different commands whether we are on Linux or Windows
* For exemple:
* git add *pom.xml on Windows
* git add '*pom.xml' on Linux */
def call(String commandLinux, String commandWindows) {
if (isUnix()) {
sh commandLinux
} else {
bat commandWindows