diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index a022d7484..74157bbe4 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -155,6 +155,7 @@ namespace GitHub.Runner.Common { public static readonly string DiskSpaceWarning = "runner.diskspace.warning"; public static readonly string Node12Warning = "DistributedTask.AddWarningToNode12Action"; + public static readonly string LogTemplateErrorsAsDebugMessages = "DistributedTask.LogTemplateErrorsAsDebugMessages"; public static readonly string UseContainerPathForTemplate = "DistributedTask.UseContainerPathForTemplate"; public static readonly string AllowRunnerContainerHooks = "DistributedTask.AllowRunnerContainerHooks"; } diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index c2a3ad2f7..fcab25a8d 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -1401,7 +1401,15 @@ namespace GitHub.Runner.Worker public void Error(string format, params Object[] args) { - _executionContext.Error(string.Format(CultureInfo.CurrentCulture, format, args)); + /* TraceWriter should be used for logging and not creating erros. */ + if (logTemplateErrorsAsDebugMessages()) + { + _executionContext.Debug(string.Format(CultureInfo.CurrentCulture, format, args)); + } + else + { + _executionContext.Error(string.Format(CultureInfo.CurrentCulture, format, args)); + } } public void Info(string format, params Object[] args) @@ -1414,8 +1422,18 @@ namespace GitHub.Runner.Worker // todo: switch to verbose? _executionContext.Debug(string.Format(CultureInfo.CurrentCulture, $"{format}", args)); } + + private bool logTemplateErrorsAsDebugMessages() + { + if (_executionContext.Global.EnvironmentVariables.TryGetValue(Constants.Runner.Features.LogTemplateErrorsAsDebugMessages, out var logErrorsAsDebug)) + { + return StringUtil.ConvertToBoolean(logErrorsAsDebug, defaultValue: false); + } + return false; + } } + public static class WellKnownTags { public static readonly string Section = "##[section]";