Jenkins - Running code in Windows agent but script says we are in Linux
I got the answer.
As Mark Waite answered here:

https://groups.google.com/forum/#!topic/jenkinsci-users/aGYt-OEYds8

Use the isUnix pipeline step rather than writing your own version of that step.  The System.properties that you are using will execute on the master, not on the agent.  When it executes on the master, it will report the os.name value of the master.