Пример #1
0
        public virtual int ExecuteProcess(DeploymentRun deploymentRun, string workingDirectory, string filename, string args)
        {
            var process = new Process();

            process.StartInfo.FileName               = filename;
            process.StartInfo.Arguments              = args;
            process.StartInfo.WorkingDirectory       = workingDirectory;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.OutputDataReceived              += (sender, data) =>
            {
                if (data.Data != null)
                {
                    _logger.LogInformation(data.Data);
                    _publisher.DeploymentRunInfo(deploymentRun, data.Data);
                }
            };
            process.StartInfo.RedirectStandardError = true;
            process.ErrorDataReceived += (sender, data) =>
            {
                if (data.Data != null)
                {
                    _logger.LogError(data.Data);
                    _publisher.DeploymentRunError(deploymentRun, data.Data);
                }
            };
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
            return(process.ExitCode);
        }
Пример #2
0
        public void Deploy(Package package, ProductEnvironment env)
        {
            foreach (var server in env.Servers.Where(s => s.ServerType.Name == package.Product.ServerType.Name))
            {
                var PackagePath   = Path.Combine(PackageRepoPath, package.PackageID.Replace("/", Path.DirectorySeparatorChar.ToString()));
                var runFilename   = Path.Combine(PackagePath, string.Format("run.{0}.{1}.{2:yyyyMMdd.HHmmss}.json", env.Name, server.Name, DateTime.Now));
                var logFilename   = runFilename.Replace(".json", ".log");
                var deploymentRun = new DeploymentRun()
                {
                    id               = Guid.NewGuid(),
                    Server           = server,
                    Variables        = env.Variables,
                    Product          = package.Product,
                    EnvironmentName  = env.Name,
                    DeploymentStatus = DeploymentStatus.Pending
                };
                NLog.MappedDiagnosticsContext.Set("Deploy.LogPath", logFilename);

                _logger.LogInformation("Deploying {0} to {1}", package.PackageID, server.Name);
                var script = Path.Combine(ScriptPath, package.Product.DeployScript);
                _logger.LogInformation("Execute: {0}", script);
                foreach (var variable in env.Variables)
                {
                    _logger.LogInformation("Variable: {0}={1}", variable.Name, variable.Value);
                }

                // Output the deployment parameters to a json run file
                using (var runFile = File.CreateText(runFilename))
                {
                    JsonSerializer.Create().Serialize(runFile, deploymentRun);
                }

                ExecuteDeploymentProcess(runFilename, deploymentRun, script);
            }
        }
Пример #3
0
        private void ExecuteDeploymentProcess(string runFilename, DeploymentRun deploymentRun, string scriptPath)
        {
            // Construct deployment runner based on script type
            IExternalProcessRunner processRunner;

            if (scriptPath.EndsWith("ps1"))
            {
                processRunner = _serviceProvider.GetRequiredService <PowershellRunner>();
            }
            else
            {
                processRunner = _serviceProvider.GetRequiredService <ProcessRunner>();
            }

            // Perform deployment and publish results
            _publisher.BeginDeploymentRun(deploymentRun);
            // Run process to perform deployment using the configuration from the run file
            var exitCode = processRunner.ExecuteProcess(deploymentRun, ScriptPath, scriptPath, runFilename);

            if (exitCode == 0)
            {
                deploymentRun.DeploymentStatus = DeploymentStatus.Success;
            }
            else
            {
                deploymentRun.DeploymentStatus = DeploymentStatus.Failure;
            }
            _logger.LogInformation("Deployment Status: {0}, exit code={1}", deploymentRun.DeploymentStatus, exitCode);
            _publisher.EndDeploymentRun(deploymentRun);
        }
Пример #4
0
        public override int ExecuteProcess(DeploymentRun deploymentRun, string workingDirectory, string script, string runFilename)
        {
            var filename = "powershell.exe";
            var args     = "&'" + script + "' " + runFilename;

            return(base.ExecuteProcess(deploymentRun, workingDirectory, filename, args));
        }