ci: refs #6695 streamline Cypress E2E test execution in Jenkinsfile and improve error handling
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
72fba4992d
commit
c660a46402
|
@ -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}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue