From 46dbd721e47f06929ecff0bd4e14c654112380ab Mon Sep 17 00:00:00 2001 From: Galindo97 Date: Wed, 20 May 2026 15:43:58 -0500 Subject: [PATCH] refactor(jenkins): mover E2E antes del deploy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit E2E corre contra la versión actualmente desplegada (A76_URL). Si los tests fallan, el deploy no ocurre — nada roto llega al servidor. Orden final: Tests (paralelo) → Security Scan → Generate Version → Docker Build → E2E → Deploy Dev → Smoke Test Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile | 122 ++++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5ceca915..10f0ad82 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ // Pipeline CI/CD — Aduanasoft Anexo76 -// Ejecuta: tests → security scan → docker build/push → deploy dev → E2E → smoke test +// Ejecuta: tests → security scan → docker build/push → E2E → deploy dev → smoke test // // Credenciales requeridas en Jenkins: // - harbor-credentials : username/password para dev.aduanasoft.com @@ -292,6 +292,66 @@ pipeline { } } + // ── E2E (Playwright) — contra la versión actualmente desplegada ───────── + // Corre ANTES del deploy con la imagen ya en Harbor pero aún no desplegada. + // Playwright apunta a A76_URL (versión viva anterior) — dominio de confianza + // para Workspace. Si E2E falla, el deploy no ocurre. + stage('E2E (Playwright)') { + when { branch 'development' } + steps { + withCredentials([ + string(credentialsId: 'a76-public-url-dev', variable: 'A76_URL'), + usernamePassword( + credentialsId: 'a76-e2e-credentials', + usernameVariable: 'E2E_USER', + passwordVariable: 'E2E_PASS' + ) + ]) { + sh ''' + set -euo pipefail + C="a76-test-e2e-${BUILD_NUMBER}" + cleanup() { docker rm -f "$C" >/dev/null 2>&1 || true; } + trap cleanup EXIT + + docker rm -f "$C" >/dev/null 2>&1 || true + docker run -d --name "$C" "$PLAYWRIGHT_IMAGE" sleep infinity + docker exec "$C" mkdir -p /workspace + docker cp "$WORKSPACE/." "$C:/workspace" + + docker exec \ + -e CI=true \ + -e "JENKINS_URL=${JENKINS_URL}" \ + -e "PLAYWRIGHT_TEST_BASE_URL=${A76_URL}" \ + -e "E2E_TEST_USER=${E2E_USER}" \ + -e "E2E_TEST_PASSWORD=${E2E_PASS}" \ + -w /workspace/frontend \ + "$C" bash -lc ' + set -euxo pipefail + npm install -g pnpm@9 --quiet + pnpm install --frozen-lockfile + pnpm run i18n:compile + + E2E_EXIT=0 + PLAYWRIGHT_JUNIT_OUTPUT_NAME=playwright-results.xml \ + pnpm exec playwright test --reporter=junit,html || E2E_EXIT=$? + + exit "$E2E_EXIT" + ' + docker cp "$C:/workspace/frontend/playwright-results.xml" \ + "$WORKSPACE/frontend/playwright-results.xml" 2>/dev/null || true + docker cp "$C:/workspace/frontend/playwright-report" \ + "$WORKSPACE/frontend/playwright-report" 2>/dev/null || true + ''' + } + } + post { + always { + junit allowEmptyResults: true, testResults: 'frontend/playwright-results.xml' + archiveArtifacts artifacts: 'frontend/playwright-report/**', allowEmptyArchive: true + } + } + } + // ── Deploy Dev ──────────────────────────────────────────────────────── stage('Deploy — Dev') { when { branch 'development' } @@ -342,66 +402,6 @@ pipeline { } } - // ── E2E (Playwright) — contra la URL desplegada ─────────────────────── - // Corre después del deploy para que Workspace confíe en el dominio de retorno. - // No levanta dev server — Playwright apunta directamente a A76_URL. - stage('E2E (Playwright)') { - when { branch 'development' } - steps { - withCredentials([ - string(credentialsId: 'a76-public-url-dev', variable: 'A76_URL'), - usernamePassword( - credentialsId: 'a76-e2e-credentials', - usernameVariable: 'E2E_USER', - passwordVariable: 'E2E_PASS' - ) - ]) { - sh ''' - set -euo pipefail - C="a76-test-e2e-${BUILD_NUMBER}" - cleanup() { docker rm -f "$C" >/dev/null 2>&1 || true; } - trap cleanup EXIT - - docker rm -f "$C" >/dev/null 2>&1 || true - docker run -d --name "$C" "$PLAYWRIGHT_IMAGE" sleep infinity - docker exec "$C" mkdir -p /workspace - docker cp "$WORKSPACE/." "$C:/workspace" - - docker exec \ - -e CI=true \ - -e "JENKINS_URL=${JENKINS_URL}" \ - -e "PLAYWRIGHT_TEST_BASE_URL=${A76_URL}" \ - -e "E2E_TEST_USER=${E2E_USER}" \ - -e "E2E_TEST_PASSWORD=${E2E_PASS}" \ - -w /workspace/frontend \ - "$C" bash -lc ' - set -euxo pipefail - npm install -g pnpm@9 --quiet - pnpm install --frozen-lockfile - pnpm run i18n:compile - - # Ejecutar E2E contra la URL desplegada - E2E_EXIT=0 - PLAYWRIGHT_JUNIT_OUTPUT_NAME=playwright-results.xml \ - pnpm exec playwright test --reporter=junit,html || E2E_EXIT=$? - - exit "$E2E_EXIT" - ' - docker cp "$C:/workspace/frontend/playwright-results.xml" \ - "$WORKSPACE/frontend/playwright-results.xml" 2>/dev/null || true - docker cp "$C:/workspace/frontend/playwright-report" \ - "$WORKSPACE/frontend/playwright-report" 2>/dev/null || true - ''' - } - } - post { - always { - junit allowEmptyResults: true, testResults: 'frontend/playwright-results.xml' - archiveArtifacts artifacts: 'frontend/playwright-report/**', allowEmptyArchive: true - } - } - } - // ── Smoke Test ──────────────────────────────────────────────────────── stage('Smoke Test') { when { branch 'development' }