From e1d07ba460ff50af2cced21a363c96a6ba8d0de6 Mon Sep 17 00:00:00 2001 From: AlexeerCT Date: Fri, 24 Apr 2026 12:33:15 -0500 Subject: [PATCH] Enhance Jenkinsfile with error handling for Docker Compose and add logging for E2E failures - Introduced a new function to log detailed error information when the Docker Compose stack fails to start, including logs from Postgres and Keycloak containers. - Updated the Docker Compose command to call the logging function upon failure, improving troubleshooting capabilities during CI runs. --- Jenkinsfile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 59bb2f57..da255c3b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -199,8 +199,23 @@ pipeline { } trap compose_down EXIT compose_down + e2e_compose_fail_logs() { + echo "== E2E: fallo al levantar stack; diagnóstico (revisa postgres-keycloak antes que keycloak) ==" + export COMPOSE_PROJECT_NAME="${E2E_COMPOSE_PROJECT}" + echo "--- docker compose ps -a ---" + docker compose -f "$WORKSPACE/docker-compose.yml" ps -a 2>&1 || true + echo "--- logs: anexo76-postgres-a76 (Postgres app) ---" + docker logs --tail 250 anexo76-postgres-a76 2>&1 || true + echo "--- logs: anexo76-postgres-keycloak (Postgres de Keycloak; el healthcheck que suele fallar) ---" + docker logs --tail 400 anexo76-postgres-keycloak 2>&1 || true + echo "--- logs: anexo76-keycloak (servidor Keycloak; a veces no alcanzó a crearse) ---" + docker logs --tail 250 anexo76-keycloak 2>&1 || true + } # Stack completo (API, Keycloak, Vite) — puede tardar varios minutos la 1.ª vez - docker compose -f "$WORKSPACE/docker-compose.yml" up -d --build + if ! docker compose -f "$WORKSPACE/docker-compose.yml" up -d --build; then + e2e_compose_fail_logs + exit 1 + fi bash "$WORKSPACE/scripts/wait-for-jenkins-stack.sh" # --network host: en Linux el contenedor de tests ve localhost:5173/8000 publicados por compose docker run --rm --network host \