gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:45:37 28 4
gpt4 key购买 nike

确定 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")
}

但即使它在 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'])
}

每个节点都在具有正确操作系统的机器上正确运行,但它们都打印 ## OS Linux
有什么想法吗?

谢谢
费德

最佳答案

据我所知,Jenkins 只区分 windows 和 unix,即如果在 windows 上,使用 bat,在 unix/mac/linux 上,使用 sh。所以你可以使用 isUnix() , more info here , 以确定您使用的是 unix 还是 windows,在 unix 的情况下,请使用 sh 和@Spencer Malone 的回答来提供有关该系统的更多信息(如果需要)。

关于grails - 如何确定 Jenkins 管道中的当前操作系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44105814/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com