diff --git a/source/Octopus.Tentacle.Core/Services/Scripts/RunningScript.cs b/source/Octopus.Tentacle.Core/Services/Scripts/RunningScript.cs index 181639758..33090d372 100644 --- a/source/Octopus.Tentacle.Core/Services/Scripts/RunningScript.cs +++ b/source/Octopus.Tentacle.Core/Services/Scripts/RunningScript.cs @@ -178,9 +178,9 @@ int RunScript(string shellPath, IScriptLogWriter writer) shellPath, shell.FormatCommandArguments(workspace.BootstrapScriptFilePath, workspace.ScriptArguments, false), workspace.WorkingDirectory, - output => writer.WriteOutput(ProcessOutputSource.Debug, output), - output => writer.WriteOutput(ProcessOutputSource.StdOut, output), - output => writer.WriteOutput(ProcessOutputSource.StdErr, output), + LogScriptOutputTo(writer, ProcessOutputSource.Debug), + LogScriptOutputTo(writer, ProcessOutputSource.StdOut), + LogScriptOutputTo(writer, ProcessOutputSource.StdErr), environmentVariables, token); @@ -194,5 +194,18 @@ int RunScript(string shellPath, IScriptLogWriter writer) return ScriptExitCodes.PowershellInvocationErrorExitCode; } } + + Action LogScriptOutputTo(IScriptLogWriter logOutput, ProcessOutputSource level) + { + try + { + return output => logOutput.WriteOutput(level, output); + } + catch (Exception e) + { + log.Warn(e, $"Could not write script output to log, for task {taskId}"); + throw; + } + } } } \ No newline at end of file