Ejemplo n.º 1
0
        private DeployAgentResult ExecuteCommand(string scriptPath, IDictionary <string, object> variables, int deploymentId)
        {
            AppDomain scriptDomain = null;

            try
            {
                scriptDomain = AppDomain.CreateDomain(string.Format("{0}:{1}", GetType(), Guid.NewGuid()),
                                                      new Evidence(AppDomain.CurrentDomain.Evidence),
                                                      AppDomain.CurrentDomain.SetupInformation);

                var proxy = (LocalPowerShellScriptExecutor)scriptDomain.CreateInstanceAndUnwrap(
                    typeof(LocalPowerShellScriptExecutor).Assembly.FullName,
                    typeof(LocalPowerShellScriptExecutor).FullName);

                _deploymentEventRecorder.SetDeploymentOutputDelegate(deploymentId, () => proxy.LiveOutput);

                var commandText = string.Format("& '{0}'", scriptPath.Replace("'", "''"));
                var result      = proxy.Execute(commandText, variables);

                return(result);
            }
            finally
            {
                if (scriptDomain != null)
                {
                    AppDomain.Unload(scriptDomain);
                }
            }
        }
Ejemplo n.º 2
0
        public DeployAgentResult Deploy(DeployAgentData deployAgentData)
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = PrepareImportGlobalVariablesScript(deployAgentData) + PrepareDeploymentScript(deployAgentData)
            };

            var runner = new PowerShellAgentRunner(request, deployAgentData.DeployScriptRoot, deployAgentData.Timeout, _clrVersion);

            if (_deploymentEventRecorder != null)
            {
                _deploymentEventRecorder.SetDeploymentOutputDelegate(deployAgentData.DeploymentId, () => runner.Output);
            }

            var exitCode = runner.Run();
            var result   = new DeployAgentResult {
                HasErrors = exitCode != 0, Output = runner.Output
            };

            return(result);
        }