diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index 0f9410821c6..4a96103fb43 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -116,6 +116,7 @@ public interface IExecutionContext : IRunnerService void FlushDeferredOutcomeConclusion(); void AddIssue(Issue issue, ExecutionContextLogOptions logOptions); + int GetErrorCount(); void Progress(int percentage, string currentOperation = null); void UpdateDetailTimelineRecord(TimelineRecord record); @@ -238,6 +239,13 @@ private ExecutionContext(ExecutionContext parent, bool embedded) // as its enclosing execution context. public bool IsEmbedded { get; private init; } + public int GetErrorCount() + { + return IsEmbedded + ? (_embeddedIssueCollector?.Count(x => x.Type == IssueType.Error) ?? 0) + : _record.ErrorCount; + } + public TaskResult? Result { get diff --git a/src/Runner.Worker/Handlers/ContainerActionHandler.cs b/src/Runner.Worker/Handlers/ContainerActionHandler.cs index 099495cb464..4a74634f68c 100644 --- a/src/Runner.Worker/Handlers/ContainerActionHandler.cs +++ b/src/Runner.Worker/Handlers/ContainerActionHandler.cs @@ -266,10 +266,16 @@ public async Task RunAsync(ActionRunStage stage) using (var stdoutManager = new OutputManager(ExecutionContext, ActionCommandManager, container)) using (var stderrManager = new OutputManager(ExecutionContext, ActionCommandManager, container)) { + var errorCountBeforeRun = ExecutionContext.GetErrorCount(); var runExitCode = await dockerManager.DockerRun(ExecutionContext, container, stdoutManager.OnDataReceived, stderrManager.OnDataReceived); ExecutionContext.Debug($"Docker Action run completed with exit code {runExitCode}"); if (runExitCode != 0) { + if (ExecutionContext.GetErrorCount() == errorCountBeforeRun) + { + ExecutionContext.Error($"Docker Action run completed with exit code {runExitCode}."); + } + ExecutionContext.Result = TaskResult.Failed; } } diff --git a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs index 85ff32777f7..5cdacbba45e 100644 --- a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs +++ b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs @@ -160,6 +160,8 @@ public async Task RunAsync(ActionRunStage stage) StepHost.OutputDataReceived += stdoutManager.OnDataReceived; StepHost.ErrorDataReceived += stderrManager.OnDataReceived; + var errorCountBeforeRun = ExecutionContext.GetErrorCount(); + // Execute the process. Exit code 0 should always be returned. // A non-zero exit code indicates infrastructural failure. // Task failure should be communicated over STDOUT using ## commands. @@ -188,6 +190,11 @@ public async Task RunAsync(ActionRunStage stage) ExecutionContext.Debug($"Node Action run completed with exit code {exitCode}"); if (exitCode != 0) { + if (ExecutionContext.GetErrorCount() == errorCountBeforeRun) + { + ExecutionContext.Error($"Node Action run completed with exit code {exitCode}."); + } + ExecutionContext.Result = TaskResult.Failed; } }