refactor: refs #8698 update Jenkinsfile to extract last successful build commit hash and improve logging
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-02-28 14:53:54 +01:00
parent d755c0c8ba
commit 69f84e2fcd
1 changed files with 13 additions and 17 deletions

30
Jenkinsfile vendored
View File

@ -86,29 +86,25 @@ pipeline {
steps {
script {
def lastSuccessfulBuild = currentBuild.previousBuild
while (lastSuccessfulBuild != null && lastSuccessfulBuild.result != 'SUCCESS') {
lastSuccessfulBuild = lastSuccessfulBuild.previousBuild
}
if (lastSuccessfulBuild != null) {
echo "Último build exitoso encontrado: #${lastSuccessfulBuild.number}"
def lastChangeSets = lastSuccessfulBuild.changesets
if (lastSuccessfulBuild) {
// Extraer el commit del build exitoso desde el changelog
def lastCommitHash = ""
lastSuccessfulBuild.changesets.each { changeSet ->
changeSet.items.each { change ->
lastCommitHash = change.commitId
}
}
// 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."
// }
if (lastCommitHash) {
echo "Último commit exitoso: ${lastCommitHash}"
}
} else {
echo "No se encontró ningún build exitoso previo."
lastCommitHash = sh(script: "git rev-parse origin/${env.CHANGE_TARGET}}", returnStdout: true).trim()
echo "Hash obtenido con git: ${lastCommitHash}"
}
}
}