public void ShouldLogErrorIfExitCode() { var logger = new StringLogger(); var parameters = new Dictionary <string, string>(); PowershellHelpers.ExecuteScript(".", "throw \"test\"", logger, parameters); logger.Logs.Count.Should().Be.EqualTo(1); logger.Logs.ElementAt(0).Error.Should().Be.True(); }
public void ShouldLogErrorIfWriteError() { var logger = new StringLogger(); var parameters = new Dictionary <string, string>(); PowershellHelpers.ExecuteScript(".", "Write-Error 'test'", logger, parameters); logger.Logs.Count.Should().Be.EqualTo(1); logger.Logs.ElementAt(0).Text.Should().Be.EqualTo("test"); logger.Logs.ElementAt(0).Error.Should().Be.True(); }
public void ShouldLogOutputofCommand() { var logger = new StringLogger(); var parameters = new Dictionary <string, string>(); PowershellHelpers.ExecuteScript(".", "&echo 'test'", logger, parameters); logger.Logs.Count.Should().Be.EqualTo(1); logger.Logs.ElementAt(0).Text.Should().Be.EqualTo("test"); logger.Logs.ElementAt(0).Error.Should().Be.False(); }
public void ShouldLogOutputIfWriteOutput() { var logger = new StringLogger(); var parameters = new Dictionary <string, string>(); parameters.Add("username", "paolo"); PowershellHelpers.ExecuteScript(".", "Write-Output $username", logger, parameters); logger.Logs.Count.Should().Be.EqualTo(1); logger.Logs.ElementAt(0).Text.Should().Be.EqualTo("paolo"); logger.Logs.ElementAt(0).Error.Should().Be.False(); }
public void ShouldLogOrderedOutputRecognizingLevel() { var logger = new StringLogger(); var parameters = new Dictionary <string, string>(); var script = @"Write-Output 'test' Write-Error 'test2' Write-Output 'test3'"; PowershellHelpers.ExecuteScript(".", script, logger, parameters); logger.Logs.Count.Should().Be.EqualTo(3); logger.Logs.ElementAt(0).Text.Should().Be.EqualTo("test"); logger.Logs.ElementAt(1).Text.Should().Be.EqualTo("test2"); logger.Logs.ElementAt(2).Text.Should().Be.EqualTo("test3"); logger.Logs.ElementAt(0).Error.Should().Be.False(); logger.Logs.ElementAt(1).Error.Should().Be.True(); logger.Logs.ElementAt(2).Error.Should().Be.False(); }
private static void LocalScriptTask(int id, int deploymentId, string version, string config) { using (var dc = new ReadContext()) { var unit = dc.LocalScriptTasks.Single(x => x.Id == id); var cwd = Environment.CurrentDirectory; var logger = new StringLogger(); using (var session = Store.OpenSession()) { session.Save(new DataAccess.Write.LogEntry() { DeploymentId = deploymentId, Error = false, TaskName = unit.Name, Text = "Executing local script " + unit.Name, TimeStamp = DateTime.UtcNow }); session.Flush(); } PowershellHelpers.ExecuteScript(cwd, unit.Script, logger, new Dictionary <string, string>()); using (var session = Store.OpenSession()) { session.Save(new DataAccess.Write.LogEntry() { DeploymentId = deploymentId, Error = false, TaskName = unit.Name, Text = String.Join("\r\n", logger.Logs.Select(x => x.Text)), TimeStamp = DateTime.UtcNow }); session.Flush(); } } }
public ExecutionResult ExecuteTemplatedTask(TemplatedTaskDto options) { var logger = new StringLogger(); try { PowershellHelpers.ExecuteScript(".", options.Script, logger, options.Parameters.ToDictionary(x => x.Name, x => x.Value)); } catch (Exception e) { return(new ExecutionResult() { Exception = e.InnerException == null ? e.Message : e.InnerException.Message, Success = false, Log = logger.Logs }); } return(new ExecutionResult() { Success = logger.Logs.All(x => !x.Error), Log = logger.Logs }); }
public ExecutionResult ExecuteScript(RemoteScriptDto options) { var logger = new StringLogger(); try { PowershellHelpers.ExecuteScript(options.Folder, options.Script, logger, new Dictionary <string, string>()); } catch (Exception e) { return(new ExecutionResult() { Exception = e.InnerException == null ? e.Message : e.InnerException.Message, Success = false, Log = logger.Logs }); } return(new ExecutionResult() { Success = logger.Logs.All(x => !x.Error), Log = logger.Logs }); }