Jenkins Mail Configuration 1729803890
Jenkins Mail Configuration 1729803890
Introduction:
Jenkins is an open source automation server that can be used for many different
actions. It is mostly used for continuous integration and continuous delivery
process in which we automate the build, test and deploy the code.
Email notifications are super important because they allow developers, testers and
stakeholders to stay informed about the build and the deployment status. These
email notifications can be sent automatically whenever the build is success, or
failed or stopped due to any other reason,
In this article, we will see two different email services configured to receive the
email from Jenkins.
Pre-requisites:
1. Gmail Account
2. Outlook Account
3. AWS Account
Basically there are two ways in which jenkins provides to send the email
notifications.
In this article, we will configure the Email Extension Plugin so that we can set
customize message and templates.
We will configure the email notification for both the email services.
GMAIL Configuration:
1. First step is to create the app password. This password will be used instead of
the Gmail password for authentication.
4. Once you’re in the security console, search for app password in the search
section.
1. Go to AWS account, search for EC2 and launch an new instance with all
default configuration.
7. Access jenkins server using your public IP and with port 8080. (Open Port
8080 in your security group).
8. Get your initial admin password from the server. Use the below command and
run it in your terminal
14. Go to manage jenkins > click on plugins and check in the installed plugin if you
have email extension plugin installed. If not, click on available plugin and install
the same.
15. Click on manage jenkins again, and click on system to configure the email.
16. Scroll down to the bottom, and check for “Extended Email notification” and
put the below values.
Click on add credentials and Give your Username (Gmail username) and
Password (App password) and save it.
19. Create a simple pipeline job and paste the below pipeline syntax in the script
section.
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
post {
always {
script {
def jobName = env.JOB_NAME
def buildNumber = env.BUILD_NUMBER
def pipelineStatus = currentBuild.result ?: 'UNK
def bannerColor = pipelineStatus.toUpperCase() =
<body>
<div style="border: 4px solid ${bannerCo
<h2>${jobName} - Build ${buildNumber
<div style="background-color: ${bann
<h3 style="color: white;">Pipeli
</div>
<p>Check the <a href="${env.BUILD_UR
</div>
</body>
</html>
"""
emailext(
subject: "${jobName} - Build ${buildNumber}
body: body,
to: 'YourEmailID'
from: 'YourEmailID',
replyTo: 'YourEmailID',
mimeType: 'text/html'
)
}
}
}
}
Replace ‘YourEmailID’ with your own Email ID. Apply and Save.
21. If your build is successful, you will receive a mail in your gmail account.
22. We will also check for any error in pipeline, and check the notification.
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo abcd
}
}
}
post {
always {
script {
def jobName = env.JOB_NAME
def buildNumber = env.BUILD_NUMBER
def pipelineStatus = currentBuild.result ?: 'UNK
def bannerColor = pipelineStatus.toUpperCase() =
<html>
<body>
<div style="border: 4px solid ${bannerCo
<h2>${jobName} - Build ${buildNumber
<div style="background-color: ${bann
<h3 style="color: white;">Pipeli
</div>
<p>Check the <a href="${env.BUILD_UR
</div>
</body>
</html>
"""
emailext(
subject: "${jobName} - Build ${buildNumber}
body: body,
to: 'YourEmailID'
from: 'YourEmailID',
replyTo: 'YourEmailID',
mimeType: 'text/html'
)
}
}
}
}
Outlook Configuration
1. Login into your outlook account.
3. Click on the mail, and forwarding and IMAP and enable both of them. Save it.
7. Once you’ve enabled the Two-step verification, you will be able to see the App
password section below.
Replace the Gmail username with the Outlook username when you’re configuring
for Outlook service. Rest all the settings remain same other than the one
mentioned above.
Create a similar job for the Outlook mail demo.
1. Create a new pipeline job and use the same script as before, but replace the
Email ID with your Outlook account address.
3. Once the build is completed, check your outlook email inbox for the
notification of the build job.
If you did not receive the email, check the jenkins console output for any error
messages related to the email notification.
Conclusion:
In conclusion, setting up the email notification in jenkins is much a simpler process
and can be completed in few steps:
Go to Jenkins and check if the email extension plugin is installed, if not then
install the same.