Jenkins To Outlook Build Email Integration
Table of contents
No headings in the article.
let’s get started :
Step 1 : We need a specified SG (security group that should have these ports opened as mentioned below)
Step 2 : launch and EC2 machine : make sure to choose t2.medium and attach the above SG into your machine .
Step 3: Connect to EC2 machine and install JDK-17 along with Jenkins and configure it :
JDK - 17 : sudo apt install openjdk-17-jre-headless -y
Jenkins (Ubuntu) :
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Step 4: go to outlook (account.live.com) » Settings » turn on 2FA and create app password .
Note : I already created app pwd which is why below Remove your app password option is showing.
Step 5 : Go to Jenkins » go to plugins » install Pipeline stage view
and check in available plugin whether Extended Email Notification
plugin downloaded » manage jenkins » fill your outlook email cred and details as mentioned in this below snap.
Step 6 : Create a pipeline job and add the pipeline script as mentioned below where added format and more details:
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 ?: 'UNKNOWN'
def bannerColor = pipelineStatus.toUpperCase() == 'SUCCESS' ? 'green' : 'red'
def body = """
<html>
<body>
<div style="border: 4px solid ${bannerColor}; padding: 10px;">
<h2>${jobName} - Build ${buildNumber}</h2>
<div style="background-color": ${bannerColor}; padding: 10px;" >
<h3 style="color: white;">Pipeline Status: ${pipelineStatus.toUpperCase()}</div>
</div>
<p>Check the <a href="${BUILD_URL}">console output</a>.</p>
</body>
</html>
"""
emailext (
subject: "${jobName} - Build #${buildNumber} - ${pipelineStatus.toUpperCase()}",
body: body,
to: 'your_email@outlook.com',
from: 'your_email@outlook.com',
replyTo: 'your_email@outlook.com',
mimeType: 'text/html'
)
}
}
}
}
I have ran the jobs for both parts - one for success job and one for failure to check whether we are good with our script or not .
This is how we can configure and integrate Jenkins and outlook for our Pipeline .