简体   繁体   English

在Jenkins上,如何确定服务器是Windows还是Linux?

[英]On Jenkins how can you detect if a server is Windows vs. Linux?

On Jenkins I'm using the Conditional BuildStep Plugin. 在Jenkins上,我使用的是条件构建步骤插件。 Is there a way to have it run some build steps depending on whether or not the slave node it's running on is Windows vs. Linux? 有没有一种方法可以使其运行某些构建步骤,具体取决于它运行的从属节点是Windows还是Linux?

You can use isUnix() function available in jenkins for identifying the OS type. 您可以使用jenkins中提供的isUnix()函数来标识操作系统类型。

So you can use something like below inside your jenkinsfile under script block:- 因此,您可以在脚本块下的jenkinsfile中使用以下内容:

 if (isUnix()) {
    sh 'ls -la'
} else {
    bat 'dir'
}

To run commands only if the current server is Windows, use the Conditional BuildStep Plugin to check: 要仅在当前服务器是Windows时运行命令,请使用条件BuildStep插件进行检查:

Strings match:
 String 1: ${ENV,var="OS"}
 String 2: Windows_NT

And to run commands only if the current server is Linux, check: 要仅在当前服务器是Linux时运行命令,请检查:

Strings match:
 String 1: ${ENV,var="OS"}
 String 2:

(Leaving String 2 blank.) (将字符串2留空。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM