How Do You Configure Jenkins Builds to Avoid Slave Servers That Are Either Windows or Linux?

Problem scenario
You are configuring Jenkins jobs.  You want certain jobs to only run on Windows slaves (e.g., PowerShell jobs) and certain jobs to only run on Linux slaves (e.g., Bash scripts).  You want to force a job force a selection of a slave server to avoid Windows or Linux servers.  How do you have Jenkins avoid slave servers based on the OS architecture?

Solution
1.  Go to the job and click on "Configure" or create a new job.

2.  Search for the word "Restrict".  

3.  Click the checkbox for Restrict.  Enter "windows" with no quotes if you want the job to only run on a Jenkins slave server running Windows.  Enter "linux" with no quotes if you want the job to only run on a Jenkins slave server running Linux.  

Optional step
There are more sophisticated restrictions you can place on the Jenkins build.  Click on the blue question mark icon on the right.  This will explain the syntax for how to force the Jenkins jobs to run on Linux or Windows exclusively.  One common usage is to use as a label the hostname of the slave server.  This will restrict the builds to this slave server exclusive of other servers.

Leave a comment

Your email address will not be published. Required fields are marked *