Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. // Global variables
  2. var objWsh = new ActiveXObject("WScript.Shell");
  3. var network = new ActiveXObject('WScript.Network');
  4. var programFiles = "C:\\Program Files (x86)\\";
  5. var arrCommands = "";
  6. var rootDeploymentPath = 'C:\\b2bDeployment\\';
  7. var scPath = rootDeploymentPath + 'KSC\\';
  8. var b2bPath = rootDeploymentPath + 'B2B\\';
  9. // Changed by arguments
  10.  
  11. var autotestsPath = "\\\\qc-tfs12\\Shared\\Builds2\\Binaries\\Endpoint-stable.Autotest\\LatestBuild";
  12. var testAgentPath = "\\\\qc-tfs12\\Shared\\Builds2\\Binaries\\TestAgent";
  13.  
  14. var rootNetDeploymentPath = '\\\\tis-dfs\\autotests\\KES\\Deployment\\Deployment_B2B\\';
  15. var scNetPath = rootNetDeploymentPath + 'KSC\\Latest';
  16. var buildPath = rootNetDeploymentPath + 'WebConsole\\Latest';
  17. var deployPath = rootNetDeploymentPath + 'Deploy\\';
  18.  
  19.  
  20.  
  21. try {
  22. Main();
  23. }
  24. catch (e) {
  25. WriteEcho("Deployment failed: " + e.message);
  26. WScript.Quit(e.number);
  27. }
  28.  
  29. function Main() {
  30. CheckInputArgs();
  31.  
  32. if (Is32BitWindows(objWsh)) {
  33. programFiles = "C:\\Program Files\\";
  34. }
  35. arrCommands = [
  36. 'cmd /c mkdir '+ rootDeploymentPath,
  37. 'cmd /c xcopy '+ rootNetDeploymentPath + 'Deploy\\* '+rootDeploymentPath+' /E /R /Y ' ,
  38. 'cscript ' + deployPath + 'CommandsProcessor.js ' + deployPath + 'Preparation.lst ' + rootNetDeploymentPath + ' ' + network.computerName,
  39. 'xcopy "' + buildPath + '\\*" "' + b2bPath + '" /E /H /R /Y',
  40. 'xcopy "' + scNetPath + '\\*" "' + scPath + '" /E /H /R /Y'];
  41. ExecuteAllCommands();
  42. }
  43.  
  44. function ExecuteAllCommands() {
  45. for (var sKey in arrCommands) {
  46. WriteEcho('Executing command: ' + arrCommands[sKey]);
  47. var arrRunExec = RunExec(arrCommands[sKey], 120 * 60 * 1000, true);
  48. if (arrRunExec['Result']) {
  49. WriteEcho('Command output: ' + arrRunExec['Output']);
  50. WriteEcho('Command succeeded');
  51. }
  52. else {
  53. if (arrRunExec['Status'] == 1) {
  54. WriteEcho('Command output: ' + arrRunExec['Output']);
  55. WriteEcho('Command failed with exit code: ' + arrRunExec['ExitCode']);
  56.  
  57. if (arrCommands[sKey].indexOf('python26') != -1) {
  58. if (arrRunExec["ExitCode"] != 0) {
  59. var newCommand = 'cmd /c c:\\python27\\python.exe "' + facadeFolder + '\\facade.py" --register';
  60. arrCommands.push(newCommand);
  61. }
  62. }
  63. else if (arrCommands[sKey].indexOf('setup.exe') != -1 || arrCommands[sKey].indexOf('.msp') != -1) {
  64. if (arrRunExec['ExitCode'] != 3010) {
  65. WriteEcho('[INSTALL_ERROR] Installer failed with exit code: ' + arrRunExec['ExitCode']);
  66. WScript.Quit(arrRunExec['ExitCode']);
  67. }
  68. }
  69. else if (arrCommands[sKey].indexOf('robocopy') != -1) {
  70. if (arrRunExec['ExitCode'] > 8) {
  71. WriteEcho('[ROBOCOPY_ERROR] Robocopy failed with exit code: ' + arrRunExec['ExitCode']);
  72. WScript.Quit(arrRunExec['ExitCode']);
  73. }
  74. }
  75. else if (arrCommands[sKey].indexOf('ipconfig') != -1) {
  76. if (arrRunExec['ExitCode'] != 0) {
  77. WriteEcho('[IPCONFIG_ERROR] Ipconfig /renew failed with exit code: ' + arrRunExec['ExitCode']);
  78. }
  79. }
  80. else {
  81. WriteEcho('[DEPLOY_ERROR] Deploy failed with exit code: ' + arrRunExec['ExitCode']);
  82. WScript.Quit(arrRunExec['ExitCode']);
  83. }
  84. }
  85. else {
  86. WriteEcho('Command terminated by timeout');
  87. WScript.Quit(999);
  88. }
  89. }
  90. if (arrCommands[sKey].indexOf('setup.exe') != -1)
  91. WScript.Sleep(30 * 1000);
  92. if (arrCommands[sKey].indexOf('net start') != -1)
  93. WScript.Sleep(5 * 1000);
  94. }
  95. }
  96.  
  97. function CheckInputArgs() {
  98. var colNamedArguments = WScript.Arguments.Named;
  99.  
  100. if (colNamedArguments.Exists("AutotestsPath"))
  101. autotestsPath = colNamedArguments.Item("AutotestsPath");
  102.  
  103. if (colNamedArguments.Exists("TestAgentPath"))
  104. testAgentPath = colNamedArguments.Item("TestAgentPath");
  105.  
  106. if (colNamedArguments.Exists("BuildPath"))
  107. buildPath = colNamedArguments.Item("BuildPath");
  108. }
  109.  
  110. // <summary>
  111. // Runs executables
  112. // </summary>
  113. // <returns type="array"></returns>
  114. function RunExec(sCommand, iMaxWait, bOutputExists) {
  115. var arrRunExec = Array();
  116. try {
  117.  
  118. var objExec = new ActiveXObject("WScript.Shell").Exec(sCommand);
  119. if (sCommand.indexOf("powershell") > -1) objExec.StdIn.Close();
  120. var strOutput = "";
  121. while (iMaxWait > 0) {
  122. if (bOutputExists) {
  123. strOut = ReadExecOut(objExec);
  124. if (strOut == -1) {
  125. if (objExec.Status == 1) break;
  126. WScript.Sleep(100);
  127. iMaxWait -= 100;
  128. }
  129. else {
  130. strOutput += strOut;
  131. }
  132. }
  133. else {
  134. if (objExec.Status == 1) break;
  135. iMaxWait -= 100;
  136. }
  137. }
  138. arrRunExec["Status"] = objExec.Status;
  139. arrRunExec["ExitCode"] = objExec.ExitCode;
  140. arrRunExec["Output"] = strOutput;
  141. arrRunExec["Result"] = false;
  142. if ((objExec.Status == 1) && (objExec.ExitCode == 0))
  143. arrRunExec["Result"] = true;
  144. if (objExec.Status == 0) {
  145. WriteEcho('Command terminated by timeout');
  146. objExec.Terminate();
  147. }
  148. return arrRunExec;
  149. }
  150. catch (objException) {
  151. WriteEcho('Command terminated with exception: ' + objException.message);
  152. arrRunExec["Result"] = false;
  153. // return false;
  154. return arrRunExec;
  155. }
  156. }
  157.  
  158. // <summary>
  159. // Reads output from objExec
  160. // </summary>
  161. // <returns type="variable"></returns>
  162. function ReadExecOut(objExec) {
  163. if (!objExec.StdOut.AtEndOfStream)
  164. return objExec.StdOut.ReadAll();
  165.  
  166. if (!objExec.StdErr.AtEndOfStream)
  167. return objExec.StdErr.ReadAll();
  168. return -1;
  169. }
  170.  
  171. // <summary>
  172. // Do WScript.Echo with time
  173. // </summary>
  174. // <returns type="variable"></returns>
  175. function WriteEcho(info) {
  176. var date = new Date();
  177. WScript.Echo(escape(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " " + info));
  178. }
  179.  
  180. function Is32BitWindows(objWsh) {
  181. var sysEnv = objWsh.Environment("System");
  182. return sysEnv("PROCESSOR_ARCHITECTURE") == "x86";
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement