twasbrillig
twasbrillig

Reputation: 18831

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

On Jenkins I'm using the Conditional BuildStep Plugin. 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?

Upvotes: 4

Views: 3359

Answers (2)

user_9090
user_9090

Reputation: 1974

You can use isUnix() function available in jenkins for identifying the OS type.

So you can use something like below inside your jenkinsfile under script block:-

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

Upvotes: 6

twasbrillig
twasbrillig

Reputation: 18831

To run commands only if the current server is Windows, use the Conditional BuildStep Plugin to check:

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

And to run commands only if the current server is Linux, check:

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

(Leaving String 2 blank.)

Upvotes: 2

Related Questions