refactor: refs #8698 update Jenkinsfile to find last successful build and remove commented test stages
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Alex Moreno 2025-02-28 14:41:27 +01:00
parent 15a6e3a3c5
commit d755c0c8ba
1 changed files with 78 additions and 47 deletions

125
Jenkinsfile vendored
View File

@ -82,58 +82,89 @@ pipeline {
sh 'pnpm install --prefer-offline'
}
}
stage('Test') {
when {
expression { !IS_PROTECTED_BRANCH }
}
environment {
NODE_ENV = ''
CI = 'true'
TZ = 'Europe/Madrid'
}
parallel {
stage('Unit') {
steps {
sh 'pnpm run test:unit:ci'
stage('Buscar último build con éxito') {
steps {
script {
def lastSuccessfulBuild = currentBuild.previousBuild
while (lastSuccessfulBuild != null && lastSuccessfulBuild.result != 'SUCCESS') {
lastSuccessfulBuild = lastSuccessfulBuild.previousBuild
}
post {
always {
junit(
testResults: 'junit/vitest.xml',
allowEmptyResults: true
)
}
}
}
stage('E2E') {
environment {
CREDENTIALS = credentials('docker-registry')
COMPOSE_PROJECT = "${PROJECT_NAME}-${env.BUILD_ID}"
COMPOSE_PARAMS = "-p ${env.COMPOSE_PROJECT} -f test/cypress/docker-compose.yml --project-directory ."
}
steps {
script {
sh 'rm junit/e2e-*.xml || true'
env.COMPOSE_TAG = PROTECTED_BRANCH.contains(env.CHANGE_TARGET) ? env.CHANGE_TARGET : 'dev'
def image = docker.build('lilium-dev', '-f docs/Dockerfile.dev docs')
sh "docker-compose ${env.COMPOSE_PARAMS} up -d"
image.inside("--network ${env.COMPOSE_PROJECT}_default -e CI -e TZ") {
sh 'cypress run --browser chromium || true'
}
}
}
post {
always {
sh "docker-compose ${env.COMPOSE_PARAMS} down -v"
junit(
testResults: 'junit/e2e-*.xml',
allowEmptyResults: true
)
}
if (lastSuccessfulBuild != null) {
echo "Último build exitoso encontrado: #${lastSuccessfulBuild.number}"
def lastChangeSets = lastSuccessfulBuild.changesets
// if (lastChangeSets.size() > 0) {
// echo "Cambios en el último build exitoso:"
// for (changeSet in lastChangeSets) {
// for (change in changeSet.items) {
// echo "Autor: ${change.author}"
// echo "Comentario: ${change.comment}"
// echo "Archivos modificados: ${change.affectedPaths}"
// }
// }
// } else {
// echo "El último build exitoso no tiene cambios registrados."
// }
} else {
echo "No se encontró ningún build exitoso previo."
}
}
}
}
// stage('Test') {
// when {
// expression { !IS_PROTECTED_BRANCH }
// }
// environment {
// NODE_ENV = ''
// CI = 'true'
// TZ = 'Europe/Madrid'
// }
// parallel {
// stage('Unit') {
// steps {
// sh 'pnpm run test:unit:ci'
// }
// post {
// always {
// junit(
// testResults: 'junit/vitest.xml',
// allowEmptyResults: true
// )
// }
// }
// }
// stage('E2E') {
// environment {
// CREDENTIALS = credentials('docker-registry')
// COMPOSE_PROJECT = "${PROJECT_NAME}-${env.BUILD_ID}"
// COMPOSE_PARAMS = "-p ${env.COMPOSE_PROJECT} -f test/cypress/docker-compose.yml --project-directory ."
// }
// steps {
// script {
// sh 'rm junit/e2e-*.xml || true'
// env.COMPOSE_TAG = PROTECTED_BRANCH.contains(env.CHANGE_TARGET) ? env.CHANGE_TARGET : 'dev'
// def image = docker.build('lilium-dev', '-f docs/Dockerfile.dev docs')
// sh "docker-compose ${env.COMPOSE_PARAMS} up -d"
// image.inside("--network ${env.COMPOSE_PROJECT}_default -e CI -e TZ") {
// sh 'cypress run --browser chromium || true'
// }
// }
// }
// post {
// always {
// sh "docker-compose ${env.COMPOSE_PARAMS} down -v"
// junit(
// testResults: 'junit/e2e-*.xml',
// allowEmptyResults: true
// )
// }
// }
// }
// }
// }
stage('Build') {
when {
expression { IS_PROTECTED_BRANCH }