小编Fed*_*deN的帖子

如何确定Jenkins管道中的当前操作系统

确定Jenkins管道正在运行的当前操作系统的方法是什么?

上下文:我正在构建一个共享的Jenkins管道脚本,该脚本应该在所有平台(windows,OSX,linux)上运行,并在每个平台上执行不同的操作.

我尝试过类似的东西:

import org.apache.commons.lang.SystemUtils

if (SystemUtils.IS_OS_WINDOWS){
   bat("Command")
}
if (SystemUtils.IS_OS_MAC){
   sh("Command")
}
if (SystemUtils.IS_OS_LINUX){
   sh("Command")
}
Run Code Online (Sandbox Code Playgroud)

但即使它在Windows或Mac上运行node它总是进入SystemUtils.IS_OS_LINUX分支

我试过像这样的快速管道.

node('windows ') {
     println ('## OS ' + System.properties['os.name'])
}
node('osx ') {
     println ('## OS ' + System.properties['os.name'])
}
node('linux') {
     println ('## OS ' + System.properties['os.name'])
}
Run Code Online (Sandbox Code Playgroud)

每个节点都在具有正确操作系统的机器中正确运行,但所有节点都打印出来 ## OS Linux

有任何想法吗?

谢谢联邦

grails jenkins jenkins-pipeline

6
推荐指数
2
解决办法
8475
查看次数

标签 统计

grails ×1

jenkins ×1

jenkins-pipeline ×1