What would be the way to determine the current OS a Jenkins pipeline is running?
Context: I\'m building a shared Jenkins pipeline script that should run on all platf
The workaround I found for this is
try{
sh(script: myScript, returnStdout: true)
}catch(Exception ex) {
//assume we are on windows
bat(script: myScript, returnStdout: true)
}
Or a little bit more elegant solution without using the try/catch is to use the env.NODE_LABELS. Assuming you have all the nodes correctly labelled you can write a function like this
def isOnWindows(){
def os = "windows"
def List nodeLabels = NODE_LABELS.split()
for (i = 0; i
and then
if (isOnWindows()) {
def osName = bat(script: command, returnStdout: true)
} else {
def osName = sh(script: command, returnStdout: true)
}