From 2f9ced96c6713f51390327e453689bbc368f7d58 Mon Sep 17 00:00:00 2001 From: AStancu Date: Tue, 6 Sep 2022 19:17:48 +0000 Subject: [PATCH] Print service containers only if they were healthy Unhealthy service logs are printed in ContainerHealthCheckLogs called prior to this step. --- .../ContainerOperationProvider.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Runner.Worker/ContainerOperationProvider.cs b/src/Runner.Worker/ContainerOperationProvider.cs index a67fda95d..ea065116e 100644 --- a/src/Runner.Worker/ContainerOperationProvider.cs +++ b/src/Runner.Worker/ContainerOperationProvider.cs @@ -302,14 +302,18 @@ namespace GitHub.Runner.Worker { if (!container.IsJobContainer) { - // Print logs for service container jobs (not the "action" job itself b/c that's already logged). - executionContext.Output($"Print service container logs: {container.ContainerDisplayName}"); + var healthcheck = await Healthcheck(executionContext, container); + if (string.Equals(healthcheck, "healthy", StringComparison.OrdinalIgnoreCase)){ + // Print logs for service container jobs (not the "action" job itself b/c that's already logged). + // Print them only if the service was healthy, else they were already logged via ContainerHealthCheckLogs. + executionContext.Output($"Print service container logs: {container.ContainerDisplayName}"); - int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId); - if (logsExitCode != 0) - { - executionContext.Warning($"Docker logs fail with exit code {logsExitCode}"); - } + int logsExitCode = await _dockerManager.DockerLogs(executionContext, container.ContainerId); + if (logsExitCode != 0) + { + executionContext.Warning($"Docker logs fail with exit code {logsExitCode}"); + } + } } executionContext.Output($"Stop and remove container: {container.ContainerDisplayName}");