Updated Jenkinsfile to be pure declarative
testing/og-dhcp-API/pipeline/head There was a failure building this commit
Details
testing/og-dhcp-API/pipeline/head There was a failure building this commit
Details
parent
a9df18a987
commit
dafcb79fc6
|
|
@ -61,61 +61,29 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
always {
|
always {
|
||||||
|
// Siempre se ejecutará, independientemente del resultado
|
||||||
script {
|
script {
|
||||||
def userCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
|
// Elimina la entrada del /etc/hosts
|
||||||
|
sh "echo '$QINDEL_PASS' | sudo -S sed -i '/api-test/d' /etc/hosts"
|
||||||
if (userCause != null) {
|
def recipientEmail = env.BUILD_USER_EMAIL ?: getCommitterEmail()
|
||||||
// Si fue lanzado manualmente, obtener el usuario y su correo desde las propiedades de Jenkins
|
|
||||||
def userId = userCause.getUserId()
|
mail to: recipientEmail,
|
||||||
def userEmail = getUserEmail(userId)
|
subject: "Jenkins Job Completed: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
|
||||||
|
body: """
|
||||||
if (userEmail) {
|
El job '${env.JOB_NAME}' con número de build ${env.BUILD_NUMBER} ha finalizado.
|
||||||
echo "El correo del usuario que lanzó el build manualmente es: ${userEmail}"
|
|
||||||
|
|
||||||
// Enviar correo al usuario que lanzó el build manualmente
|
Estado: ${currentBuild.currentResult}
|
||||||
mail to: "${userEmail}",
|
|
||||||
subject: "Jenkins Job Completed (Manual): ${env.JOB_NAME} #${env.BUILD_NUMBER}",
|
Revisa los detalles del build en: ${env.BUILD_URL}
|
||||||
body: """
|
"""
|
||||||
El job '${env.JOB_NAME}' con número de build ${env.BUILD_NUMBER} ha finalizado (ejecutado manualmente).
|
|
||||||
|
|
||||||
Estado: ${currentBuild.currentResult}
|
|
||||||
|
|
||||||
Revisa los detalles del build en: ${env.BUILD_URL}
|
|
||||||
"""
|
|
||||||
} else {
|
|
||||||
echo "No se pudo encontrar un correo electrónico para el usuario: ${userId}"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Si fue lanzado automáticamente, obtener el correo del committer
|
|
||||||
def committerEmail = sh(
|
|
||||||
script: 'git log -1 --pretty=format:"%ae"',
|
|
||||||
returnStdout: true
|
|
||||||
).trim()
|
|
||||||
|
|
||||||
echo "El build fue lanzado automáticamente. Correo del committer: ${committerEmail}"
|
|
||||||
|
|
||||||
// Enviar correo al committer
|
|
||||||
mail to: "${committerEmail}",
|
|
||||||
subject: "Jenkins Job Completed (Automático): ${env.JOB_NAME} #${env.BUILD_NUMBER}",
|
|
||||||
body: """
|
|
||||||
El job '${env.JOB_NAME}' con número de build ${env.BUILD_NUMBER} ha finalizado (ejecutado automáticamente).
|
|
||||||
|
|
||||||
Estado: ${currentBuild.currentResult}
|
|
||||||
|
|
||||||
Revisa los detalles del build en: ${env.BUILD_URL}
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonCPS
|
def getCommitterEmail() {
|
||||||
def getUserEmail(userId) {
|
return sh(
|
||||||
def jenkinsInstance = currentBuild.rawBuild.getParent().getParent()
|
script: 'git log -1 --pretty=format:"%ae"',
|
||||||
if (jenkinsInstance != null) {
|
returnStdout: true
|
||||||
def user = jenkinsInstance.getUser(userId)
|
).trim()
|
||||||
return user.getProperty(jenkins.plugins.mailer.tasks.Mailer.UserProperty)?.getAddress()
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue