diff --git a/Jenkinsfile b/Jenkinsfile index 55b4f6046..3a1a8a98d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -110,11 +110,17 @@ pipeline { stage('Run') { steps { script { - sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up -d back" - sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up -d front" - sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up e2e" - checkErrors(folderName) - } + sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up -d" + def containerId = sh(script: """ + docker run --network \${env.NETWORK}_e2e-network \\ + -e TZ=Europe/Madrid \\ + -e DOCKER=true \\ + -v \$(pwd):/app \\ + -w /app \\ + cypress/included:latest \\ + sh -c "while [ ! -d node_modules/cypress ]; do sleep 1; done && pnpm exec cypress run --browser chromium" + """, returnStdout: true).trim() + checkErrors(containerId)} } } } @@ -163,28 +169,18 @@ pipeline { def cleanDockerE2E() { script { - def projectBranch = "${PROJECT_NAME}-${env.BRANCH_NAME}".toLowerCase() - sh """ - docker ps -a --filter 'name=^${projectBranch}' | awk 'NR>1 {print \"\$1\"}' | xargs -r -I {} sh -c 'docker stop {} && docker rm -v {}' || true - """ - sh """ - docker network ls --filter 'name=^${projectBranch}' | awk 'NR>1 {print \"\$1\"}' | xargs -r docker network rm || true - """ - + sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml down" + sh "docker rm ${containerId}" } } -def checkErrors(String folderName){ - def containerId = sh(script: "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml ps -q e2e", returnStdout: true).trim() - if (containerId) { - def exitCode = sh(script: "docker inspect -f '{{.State.ExitCode}}' ${containerId}", returnStdout: true).trim() - // sh "sudo docker cp ${containerId}:/app/test/cypress/reports ./test/cypress/" - if (exitCode != '0') { - def logs = sh(script: "docker logs ${containerId}", returnStdout: true).trim() - error("Cypress E2E tests failed with exit code: ${exitCode}\nLogs:\n${logs}") - } - } else { - error("The Docker container for E2E tests could not be created") +def checkErrors(String containerId) { + echo "Container ID: ${containerId}" + def exitCode = sh(script: "docker inspect -f '{{.State.ExitCode}}' ${containerId}", returnStdout: true).trim() + echo "Exit code: ${exitCode}" + if (exitCode != '0') { + def logs = sh(script: "docker logs ${containerId}", returnStdout: true).trim() + error("Cypress E2E tests failed with exit code: ${exitCode}\nLogs:\n${logs}") } } diff --git a/docker-compose.e2e.yml b/docker-compose.e2e.yml index d8b266cd0..53b80a78d 100644 --- a/docker-compose.e2e.yml +++ b/docker-compose.e2e.yml @@ -16,14 +16,14 @@ services: environment: - TZ=Europe/Madrid - DOCKER=true - e2e: - image: cypress-setup:latest - command: sh -c "while [ ! -d node_modules/cypress ]; do sleep 1; done && pnpm exec cypress run --browser chromium" - environment: - - TZ=Europe/Madrid - - DOCKER=true - volumes: - - .:/app - working_dir: /app + # e2e: + # image: cypress-setup:latest + # command: sh -c "while [ ! -d node_modules/cypress ]; do sleep 1; done && pnpm exec cypress run --browser chromium" + # environment: + # - TZ=Europe/Madrid + # - DOCKER=true + # volumes: + # - .:/app + # working_dir: /app vn-database: image: registry.verdnatura.es/salix-db:dev diff --git a/test/cypress/docker/run/run_group.sh b/test/cypress/docker/run/run_group.sh index b8311265b..e3a202987 100644 --- a/test/cypress/docker/run/run_group.sh +++ b/test/cypress/docker/run/run_group.sh @@ -89,7 +89,7 @@ run_group() { exit_code=$(docker inspect -f '{{.State.ExitCode}}' "$container_id" 2>/dev/null || echo "1") if [[ "$exit_code" -ne 0 ]]; then - echo "⚠️ Error en la ejecución de ${folderName} (Exit Code: $exit_code)" + echo "❌ Error en la ejecución de ${folderName} (Exit Code: $exit_code)" buildResult="UNSTABLE" docker logs "$container_id" > "test/cypress/docker/logs/${uniqueName}.log" 2>/dev/null || true failedTests+=("$folderName")