Fed*_*deN 6 grails jenkins jenkins-pipeline
确定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
有任何想法吗?
谢谢联邦
fed*_*rzi 13
假设您将Windows作为唯一的非unix平台,您可以使用管道功能isUnix()并uname检查您所在的Unix操作系统:
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"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8475 次 |
| 最近记录: |