Reputation: 18831
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
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
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