First when you are declaring a new variable be sure to use var unless you intention is to make it globally accessible. I'm guessing this line:
Build=vCACVmProperties.get('VirtualMachine.BuildType');
should be:
var Build=vCACVmProperties.get('VirtualMachine.BuildType');
I'm not positive how all the scoping shakes out in vRO but if you haven't read up on variable scoping in javascript I'd take a look here JavaScript Scope.
and I think this is the line you want for setting cmd:
var cmd='sed -i -e \"s/CURRENTHOSTNAME/' + newHostName + '/g\" /etc/hosts';
You need to escape the " and also forgot a plust sign between the strings and the variable.