ci: refs #8698 try lastSuccessfulBuild
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-03-03 13:49:31 +01:00
parent d199478c1d
commit 5c627dd489
2 changed files with 117 additions and 62 deletions

178
Jenkinsfile vendored
View File

@ -28,11 +28,66 @@ def searchFiles = { searchString ->
return extractedFolders
}
def getSpec(path){
def getSpec(path) {
return "test/cypress/integration/" + path.split("/")[2] + "/**/*.spec.js"
}
def getSpecs() {
def lastCommit
def lastSuccessfulBuild = currentBuild.previousBuild
def currentCommit = sh(
script: "git rev-parse HEAD",
returnStdout: true
).trim()
def files = []
while (lastSuccessfulBuild != null && lastSuccessfulBuild.result != 'SUCCESS') {
lastSuccessfulBuild = lastSuccessfulBuild.previousBuild
}
if (lastSuccessfulBuild != null && lastSuccessfulBuild.changeSets.size() > 0) {
for (changeSet in lastSuccessfulBuild.changeSets) {
for (change in changeSet.items) {
lastCommit = change.commitId
break
}
}
if (lastCommit) {
echo "Último commit exitoso: ${lastCommit}"
}
}
if(!lastCommit) {
lastCommit = sh(script: "git rev-parse origin/${env.CHANGE_TARGET}}", returnStdout: true).trim()
echo "Hash obtenido con git: ${lastCommit}"
}
def modifiedFiles = sh(
script: "git diff --name-only ${lastCommit} ${currentCommit}",
returnStdout: true
).trim().split("\n")
modifiedFiles.each { file ->
echo "- ${file}"
if(!file.startsWith('src/pages')){
if(file.startsWith('test/cypress/integration')){
files.add(file)
}
//else {
// files = 'test/cypress/integration/**/*.spec.js'
// return
// }
} else{
files = (files + searchFiles(file)).unique()
}
}
return files
}
node {
stage('Setup') {
env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev'
@ -98,14 +153,14 @@ pipeline {
}
}
}
// stage('Install') {
// environment {
// NODE_ENV = ""
// }
// steps {
// sh 'pnpm install --prefer-offline'
// }
// }
stage('Install') {
environment {
NODE_ENV = ""
}
steps {
sh 'pnpm install --prefer-offline'
}
}
stage('Buscar último build con éxito') {
steps {
script {
@ -163,58 +218,59 @@ pipeline {
}
}
}
// stage('Test') {
// when {
// expression { !IS_PROTECTED_BRANCH }
// }
// environment {
// NODE_ENV = ''
// CI = 'true'
// TZ = 'Europe/Madrid'
// }
// parallel {
// stage('Unit') {
// steps {
// sh 'pnpm run test:front: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('Test') {
when {
expression { !IS_PROTECTED_BRANCH }
}
environment {
NODE_ENV = ''
CI = 'true'
TZ = 'Europe/Madrid'
}
parallel {
stage('Unit') {
steps {
sh 'pnpm run test:front: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 --spec ${getFiles()} || 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 }

View File

@ -51,7 +51,6 @@ async function onSubmit() {
});
}
}
// REMOVE:
</script>
<template>