How to determine the current operating system in a Jenkins pipeline

后端 未结 5 1316
醉梦人生
醉梦人生 2020-12-28 21:31

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

5条回答
  •  滥情空心
    2020-12-28 21:55

    Assuming you have Windows as your only non-unix platform, you can use the pipeline function isUnix() and uname to check on which Unix OS you're on:

    def checkOs(){
        if (isUnix()) {
            def uname = sh script: 'uname', returnStdout: true
            if (uname.startsWith("Darwin")) {
                return "Macos"
            }
            // Optionally add 'else if' for other Unix OS  
            else {
                return "Linux"
            }
        }
        else {
            return "Windows"
        }
    }
    

提交回复
热议问题