Change script to get user email

nginx_conf
Nicolas Arenas 2024-10-01 13:58:58 +02:00
parent 3d458453ed
commit 3793256ae8
1 changed files with 13 additions and 5 deletions

View File

@ -38,27 +38,29 @@ pipeline {
}
}
}
stage ('Run API tests') {
stage('Run API tests') {
steps {
echo 'Running API tests'
// Aquí incluirías los comandos para ejecutar tus pruebas
}
}
}
post {
success {
script {
// Si el trabajo ha sido exitoso, destruir la máquina de Vagrant
echo "El trabajo ha finalizado con éxito. Destruyendo máquina Vagrant..."
dir ('tests/API-dhcp') {
sh 'vagrant destroy -f'
}
}
always {
script {
def userCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
if (userCause != null) {
// Si fue lanzado manualmente, obtener el usuario y su correo desde las propiedades de Jenkins
def userId = userCause.getUserId()
def user = jenkins.model.Jenkins.instance.getUser(userId)
def userEmail = user.getProperty(jenkins.plugins.mailer.tasks.Mailer.UserProperty)?.getAddress()
def userEmail = getUserEmail(userId)
if (userEmail) {
echo "El correo del usuario que lanzó el build manualmente es: ${userEmail}"
@ -100,3 +102,9 @@ pipeline {
}
}
}
@NonCPS
def getUserEmail(userId) {
def user = jenkins.model.Jenkins.instance.getUser(userId)
return user.getProperty(jenkins.plugins.mailer.tasks.Mailer.UserProperty)?.getAddress()
}