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') {
|
stage('Run') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
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"
|
||||||
sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up -d front"
|
def containerId = sh(script: """
|
||||||
sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up e2e"
|
docker run --network \${env.NETWORK}_e2e-network \\
|
||||||
checkErrors(folderName)
|
-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() {
|
def cleanDockerE2E() {
|
||||||
script {
|
script {
|
||||||
def projectBranch = "${PROJECT_NAME}-${env.BRANCH_NAME}".toLowerCase()
|
sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml down"
|
||||||
sh """
|
sh "docker rm ${containerId}"
|
||||||
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
|
|
||||||
"""
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkErrors(String folderName){
|
def checkErrors(String containerId) {
|
||||||
def containerId = sh(script: "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml ps -q e2e", returnStdout: true).trim()
|
echo "Container ID: ${containerId}"
|
||||||
if (containerId) {
|
def exitCode = sh(script: "docker inspect -f '{{.State.ExitCode}}' ${containerId}", returnStdout: true).trim()
|
||||||
def exitCode = sh(script: "docker inspect -f '{{.State.ExitCode}}' ${containerId}", returnStdout: true).trim()
|
echo "Exit code: ${exitCode}"
|
||||||
// sh "sudo docker cp ${containerId}:/app/test/cypress/reports ./test/cypress/"
|
if (exitCode != '0') {
|
||||||
if (exitCode != '0') {
|
def logs = sh(script: "docker logs ${containerId}", returnStdout: true).trim()
|
||||||
def logs = sh(script: "docker logs ${containerId}", returnStdout: true).trim()
|
error("Cypress E2E tests failed with exit code: ${exitCode}\nLogs:\n${logs}")
|
||||||
error("Cypress E2E tests failed with exit code: ${exitCode}\nLogs:\n${logs}")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error("The Docker container for E2E tests could not be created")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,14 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Madrid
|
- TZ=Europe/Madrid
|
||||||
- DOCKER=true
|
- DOCKER=true
|
||||||
e2e:
|
# e2e:
|
||||||
image: cypress-setup:latest
|
# image: cypress-setup:latest
|
||||||
command: sh -c "while [ ! -d node_modules/cypress ]; do sleep 1; done && pnpm exec cypress run --browser chromium"
|
# command: sh -c "while [ ! -d node_modules/cypress ]; do sleep 1; done && pnpm exec cypress run --browser chromium"
|
||||||
environment:
|
# environment:
|
||||||
- TZ=Europe/Madrid
|
# - TZ=Europe/Madrid
|
||||||
- DOCKER=true
|
# - DOCKER=true
|
||||||
volumes:
|
# volumes:
|
||||||
- .:/app
|
# - .:/app
|
||||||
working_dir: /app
|
# working_dir: /app
|
||||||
vn-database:
|
vn-database:
|
||||||
image: registry.verdnatura.es/salix-db:dev
|
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")
|
exit_code=$(docker inspect -f '{{.State.ExitCode}}' "$container_id" 2>/dev/null || echo "1")
|
||||||
|
|
||||||
if [[ "$exit_code" -ne 0 ]]; then
|
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"
|
buildResult="UNSTABLE"
|
||||||
docker logs "$container_id" > "test/cypress/docker/logs/${uniqueName}.log" 2>/dev/null || true
|
docker logs "$container_id" > "test/cypress/docker/logs/${uniqueName}.log" 2>/dev/null || true
|
||||||
failedTests+=("$folderName")
|
failedTests+=("$folderName")
|
||||||
|
|
Loading…
Reference in New Issue