Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Global variables
- var objWsh = new ActiveXObject("WScript.Shell");
- var network = new ActiveXObject('WScript.Network');
- var programFiles = "C:\\Program Files (x86)\\";
- var arrCommands = "";
- var rootDeploymentPath = 'C:\\b2bDeployment\\';
- var scPath = rootDeploymentPath + 'KSC\\';
- var b2bPath = rootDeploymentPath + 'B2B\\';
- // Changed by arguments
- var autotestsPath = "\\\\qc-tfs12\\Shared\\Builds2\\Binaries\\Endpoint-stable.Autotest\\LatestBuild";
- var testAgentPath = "\\\\qc-tfs12\\Shared\\Builds2\\Binaries\\TestAgent";
- var rootNetDeploymentPath = '\\\\tis-dfs\\autotests\\KES\\Deployment\\Deployment_B2B\\';
- var scNetPath = rootNetDeploymentPath + 'KSC\\Latest';
- var buildPath = rootNetDeploymentPath + 'WebConsole\\Latest';
- var deployPath = rootNetDeploymentPath + 'Deploy\\';
- try {
- Main();
- }
- catch (e) {
- WriteEcho("Deployment failed: " + e.message);
- WScript.Quit(e.number);
- }
- function Main() {
- CheckInputArgs();
- if (Is32BitWindows(objWsh)) {
- programFiles = "C:\\Program Files\\";
- }
- arrCommands = [
- 'cmd /c mkdir '+ rootDeploymentPath,
- 'cmd /c xcopy '+ rootNetDeploymentPath + 'Deploy\\* '+rootDeploymentPath+' /E /R /Y ' ,
- 'cscript ' + deployPath + 'CommandsProcessor.js ' + deployPath + 'Preparation.lst ' + rootNetDeploymentPath + ' ' + network.computerName,
- 'xcopy "' + buildPath + '\\*" "' + b2bPath + '" /E /H /R /Y',
- 'xcopy "' + scNetPath + '\\*" "' + scPath + '" /E /H /R /Y'];
- ExecuteAllCommands();
- }
- function ExecuteAllCommands() {
- for (var sKey in arrCommands) {
- WriteEcho('Executing command: ' + arrCommands[sKey]);
- var arrRunExec = RunExec(arrCommands[sKey], 120 * 60 * 1000, true);
- if (arrRunExec['Result']) {
- WriteEcho('Command output: ' + arrRunExec['Output']);
- WriteEcho('Command succeeded');
- }
- else {
- if (arrRunExec['Status'] == 1) {
- WriteEcho('Command output: ' + arrRunExec['Output']);
- WriteEcho('Command failed with exit code: ' + arrRunExec['ExitCode']);
- if (arrCommands[sKey].indexOf('python26') != -1) {
- if (arrRunExec["ExitCode"] != 0) {
- var newCommand = 'cmd /c c:\\python27\\python.exe "' + facadeFolder + '\\facade.py" --register';
- arrCommands.push(newCommand);
- }
- }
- else if (arrCommands[sKey].indexOf('setup.exe') != -1 || arrCommands[sKey].indexOf('.msp') != -1) {
- if (arrRunExec['ExitCode'] != 3010) {
- WriteEcho('[INSTALL_ERROR] Installer failed with exit code: ' + arrRunExec['ExitCode']);
- WScript.Quit(arrRunExec['ExitCode']);
- }
- }
- else if (arrCommands[sKey].indexOf('robocopy') != -1) {
- if (arrRunExec['ExitCode'] > 8) {
- WriteEcho('[ROBOCOPY_ERROR] Robocopy failed with exit code: ' + arrRunExec['ExitCode']);
- WScript.Quit(arrRunExec['ExitCode']);
- }
- }
- else if (arrCommands[sKey].indexOf('ipconfig') != -1) {
- if (arrRunExec['ExitCode'] != 0) {
- WriteEcho('[IPCONFIG_ERROR] Ipconfig /renew failed with exit code: ' + arrRunExec['ExitCode']);
- }
- }
- else {
- WriteEcho('[DEPLOY_ERROR] Deploy failed with exit code: ' + arrRunExec['ExitCode']);
- WScript.Quit(arrRunExec['ExitCode']);
- }
- }
- else {
- WriteEcho('Command terminated by timeout');
- WScript.Quit(999);
- }
- }
- if (arrCommands[sKey].indexOf('setup.exe') != -1)
- WScript.Sleep(30 * 1000);
- if (arrCommands[sKey].indexOf('net start') != -1)
- WScript.Sleep(5 * 1000);
- }
- }
- function CheckInputArgs() {
- var colNamedArguments = WScript.Arguments.Named;
- if (colNamedArguments.Exists("AutotestsPath"))
- autotestsPath = colNamedArguments.Item("AutotestsPath");
- if (colNamedArguments.Exists("TestAgentPath"))
- testAgentPath = colNamedArguments.Item("TestAgentPath");
- if (colNamedArguments.Exists("BuildPath"))
- buildPath = colNamedArguments.Item("BuildPath");
- }
- // <summary>
- // Runs executables
- // </summary>
- // <returns type="array"></returns>
- function RunExec(sCommand, iMaxWait, bOutputExists) {
- var arrRunExec = Array();
- try {
- var objExec = new ActiveXObject("WScript.Shell").Exec(sCommand);
- if (sCommand.indexOf("powershell") > -1) objExec.StdIn.Close();
- var strOutput = "";
- while (iMaxWait > 0) {
- if (bOutputExists) {
- strOut = ReadExecOut(objExec);
- if (strOut == -1) {
- if (objExec.Status == 1) break;
- WScript.Sleep(100);
- iMaxWait -= 100;
- }
- else {
- strOutput += strOut;
- }
- }
- else {
- if (objExec.Status == 1) break;
- iMaxWait -= 100;
- }
- }
- arrRunExec["Status"] = objExec.Status;
- arrRunExec["ExitCode"] = objExec.ExitCode;
- arrRunExec["Output"] = strOutput;
- arrRunExec["Result"] = false;
- if ((objExec.Status == 1) && (objExec.ExitCode == 0))
- arrRunExec["Result"] = true;
- if (objExec.Status == 0) {
- WriteEcho('Command terminated by timeout');
- objExec.Terminate();
- }
- return arrRunExec;
- }
- catch (objException) {
- WriteEcho('Command terminated with exception: ' + objException.message);
- arrRunExec["Result"] = false;
- // return false;
- return arrRunExec;
- }
- }
- // <summary>
- // Reads output from objExec
- // </summary>
- // <returns type="variable"></returns>
- function ReadExecOut(objExec) {
- if (!objExec.StdOut.AtEndOfStream)
- return objExec.StdOut.ReadAll();
- if (!objExec.StdErr.AtEndOfStream)
- return objExec.StdErr.ReadAll();
- return -1;
- }
- // <summary>
- // Do WScript.Echo with time
- // </summary>
- // <returns type="variable"></returns>
- function WriteEcho(info) {
- var date = new Date();
- WScript.Echo(escape(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " " + info));
- }
- function Is32BitWindows(objWsh) {
- var sysEnv = objWsh.Environment("System");
- return sysEnv("PROCESSOR_ARCHITECTURE") == "x86";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement