Change script to get user email
	
		
			
	
		
	
	
		
			
				
	
				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
							
								
									c9764a99d3
								
							
						
					
					
						commit
						231cbe92d8
					
				|  | @ -41,24 +41,26 @@ pipeline { | ||||||
|         stage('Run API tests') { |         stage('Run API tests') { | ||||||
|             steps { |             steps { | ||||||
|                 echo 'Running API tests' |                 echo 'Running API tests' | ||||||
|  |                 // Aquí incluirías los comandos para ejecutar tus pruebas | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     post { |     post { | ||||||
|         success { |         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..." |             echo "El trabajo ha finalizado con éxito. Destruyendo máquina Vagrant..." | ||||||
|  |             dir ('tests/API-dhcp') { | ||||||
|                 sh 'vagrant destroy -f' |                 sh 'vagrant destroy -f' | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         always { |         always { | ||||||
|             script { |             script { | ||||||
|                 def userCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) |                 def userCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) | ||||||
|  |                  | ||||||
|                 if (userCause != null) { |                 if (userCause != null) { | ||||||
|                     // Si fue lanzado manualmente, obtener el usuario y su correo desde las propiedades de Jenkins |                     // Si fue lanzado manualmente, obtener el usuario y su correo desde las propiedades de Jenkins | ||||||
|                     def userId = userCause.getUserId() |                     def userId = userCause.getUserId() | ||||||
|                     def user = jenkins.model.Jenkins.instance.getUser(userId) |                     def userEmail = getUserEmail(userId) | ||||||
|                     def userEmail = user.getProperty(jenkins.plugins.mailer.tasks.Mailer.UserProperty)?.getAddress() |  | ||||||
|                      |                      | ||||||
|                     if (userEmail) { |                     if (userEmail) { | ||||||
|                         echo "El correo del usuario que lanzó el build manualmente es: ${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() | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue