Print service containers only if they were healthy

Unhealthy service logs are printed in ContainerHealthCheckLogs called prior to this step.
This commit is contained in:
AStancu
2022-09-06 19:17:48 +00:00
parent 29e26c0aa1
commit 2f9ced96c6

View File

@@ -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}");