How to determine the current operating system in a Jenkins pipeline

后端 未结 5 1309
醉梦人生
醉梦人生 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:38

    Using Java classes is probably not the best approach. I'm pretty sure that unless it's a jenkins / groovy plugin, those run on the master Jenkins JVM thread. I would look into a shell approach, such as the one outlined here: https://stackoverflow.com/a/8597411/5505255

    You could wrap that script in a shell step to get the stdout like so:

    def osName = sh(script: './detectOS', returnStdout: true)
    

    to call a copy of the script being outlined above. Then just have that script return the OS names you want, and branch logic based on the osName var.

提交回复
热议问题