How to identify Jenkins Slave Operating System in a Build

8 Responses

  1. Satish says:

    Hi, thanks for the suggestions in the post. Although it works, the console output will be a bit messy if you choose to run a shell command & windows command in the conditions (With Jenkins ignoring the failed method). Alternate method which worked for me & looked a bit cleaner is choosing the node option in the Step condition. If you have multiple nodes with the same OS, then you can multi select the right nodes.

    • Chintan Mehta says:

      Hi, Yes you are right but here my concern is I have one jenkins job which I am not sure on which OS i will run. Depending on scenarios I may run it on Windows or Linux. I didn’t want to change anything on job so above option will automatically handle OS and execute appropriate shell commands or windows command.
      If you have got what I mean and have some good options plz suggest so I can share.
      Thanks

  2. Ivan says:

    Hi,

    I had the same problem and I just fixed it doing a ‘strings match’ on the environment variables for the logged-in user name.

    Linux:
    String1: ${ENV,var=”USER”}
    String2: jenkins

    Windows:
    String1: ${ENV,var=”USERNAME”}
    String2: jenkins

    I hope it helps.

    • Ryan says:

      I would argue that this is the best method listed here. It prevents any java IO api errors from corrupting the console output (that other steps in the build procedure may act upon).

  3. Philip says:

    Lot’s can be done cross platform by implementing it as python or groovy scripts

  4. ravi says:

    What if the Slave machine is a MAC OS? How to find it?

    • techiepie says:

      With the similar approach, I would find a command which is not present on Linux and available on Mac to detect exception. Never got chance to make mac slave machine. Would update if I ever get.

Leave a Reply