Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch TemplateTraceWriter on ExecutionContext to not create error annotations on TraceError #2656

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Runner.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static class Features
{
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";
}
Expand Down
20 changes: 19 additions & 1 deletion src/Runner.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,15 @@ internal TemplateTraceWriter(IExecutionContext executionContext)

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)
Expand All @@ -1414,8 +1422,18 @@ public void Verbose(string format, params Object[] args)
// 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]";
Expand Down