Jenkins Continuous Deployment - Email Notification with ChangeLog
·
2 min read
·
357
Words
·
-Views
-Comments
To enable timely notifications to BA and Dev colleagues after production releases, I spent some time researching Jenkins over the weekend. Here’s a simple markdown summary.
Installation and Configuration
Plugin Manager
The built-in mail plugin is too simple. To achieve email template customization, the following plugins need to be installed:
Jenkins Configuration
The Extension plugin is different from the built-in mail plugin and requires separate email server configuration
Template Creation
Instead of directly logging into the Jenkins deployment server for file operations, you can use the GUI directly. Here I chose the GUI approach:
Managed files => Add a new Config => Extended Email Publisher Groovy Template
Notes
- This configuration will be in the service root directory, use ‘groovy-html.template’ directly when needed
- The template I chose here is based on modifications of the official plugin’s provided templates. Plugin templates are not installed by default, so manual configuration is required:
- Plugin template download click here
- My improved template for sending Git ChangeLog click here
Pipeline Configuration
properties([buildDiscarder(logRotator(artifactNumToKeepStr: '10', numToKeepStr: '10'))])
node() {
try {
currentBuild.result = 'SUCCESS'
}
catch (err) {
currentBuild.result = 'FAILURE'
}
finally {
stage ('Notify') {
emailext to: 'alan@1991421.cn',
recipientProviders: [[$class: 'RequesterRecipientProvider'],[$class: 'DevelopersRecipientProvider']],
subject: "Production deployment: ${currentBuild.fullDisplayName} ${currentBuild.result}",
body: '''${SCRIPT,template="managed:groovy-html.template"}'''
mimeType: 'text/html'
}
}
}
Notes
- try catch should be at the outermost level
- mimeType is recommended to be explicitly specified, as in some versions it may cause emails to be sent as HTML text without proper rendering
Results
The following is the final email sent:
- It’s important to know that even if the final notification indicates a successful release, if it’s a Java service, the container startup actually takes time. Depending on the specific container service configuration, the effective delay will vary. So strictly speaking, a successful email notification doesn’t necessarily mean it’s
simultaneously effective and online
Final Thoughts
- Personally, I think the documentation for Jenkins and its surrounding plugins is quite average. Comparatively speaking, looking at practical books is more efficient than reading official documentation and Googling
- I recommend the book I’m currently reading 《Jenkins 2: Up and Running》