Setup Jenkins Pipeline Email

Devops Tutorial 31 – Setup Jenkins pipeline Email

On the Jenkins dashboard, you would see ‘Manage Jenkins’​​ 

Click ‘Manage Jenkins’

Click ‘Configure System’ seen above.

Scroll down,​​ you would see ‘E-mail Notification’ section shown below

Enter​​ smtp.gmail.com​​ in SMTP server field

Click ‘Advanced’ that you see above

The below additional fields would come up

Select the checkbox ‘Use SMTP Authentication’

Enter gmail id and password (you can create a dummy gmail account and use it here)

Select ‘Use SSL’ checkbox

Enter SMTP port as 465

Select ‘Test configuration by sending test e-mail‘ checkbox​​ 

Enter any email id

Click ‘Test configuration’

You might get the below error

To resolve this error, login to above gmail account (log out from other gmail accounts).

Also Check:​​ Selenium Webdriver Training

Once you are logged in, launch below url

https://www.google.com/settings/security/lesssecureapps​​ 

Switch ON the below setting

Click ‘Test configuration’ again, you should now see the below message ‘Email was successfully sent’​​ 

Open the above gmail account, you would see a new email as shown below​​ 

Click Save to save the configuration

Let​​ us now write jenkins pipeline code for sending email notifications.

Create new pipeline job​​ 

Click ‘Pipeline Syntax’ link

Select ‘mail: Mail’ from dropdown as shown below

Enter email id in the ‘To’ field

Enter subject and Body

Click ‘Generate​​ Pipeline Script’ ​​ 

Copy this code:

mail bcc: '', body: 'Hello, This is an email from jenkins pipeline.', cc: '', from: '', replyTo: '', subject: 'EmailJenkinsPipeline', to: 'sskg12035@gmail.com'

Paste it in the pipeline code as shown below

Below is the entire code:

pipeline {

 ​​ ​​ ​​​​ agent any

 ​​ ​​ ​​​​ stages {

 ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ stage('Email Jenkins Pipeline') {

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ steps {

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ mail bcc: '', body: 'Hello, This is an email from jenkins pipeline.', cc: '', from: '', replyTo: '', subject:​​ 'EmailJenkinsPipeline', to: 'sskg12035@gmail.com'

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ }

 ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ }  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ 

 ​​ ​​ ​​​​ }

}

Paste this code in jenkins pipeline job

Apply and Save

Click ‘Build Now’

Wait for the job to get over


Refresh the gmail account, you would see an​​ email

Once you are done, change back the security settings

https://www.google.com/settings/security/lesssecureapps​​ 

Thank you for reading!

Also Check:​​ Selenium Tutorials

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 31st DEC 2024