Jenkins中配置邮件通知的方法和实例演练
2018-01-31 17:55
375 查看
一、文章意图
本文通过安装配置Jenkins实现邮件通知,告知一个C# GitRepo的build成功与否二、预配条件
1.在windows上安装Jenkins和它推荐安装的Plugins2.创建一个@163.com邮箱账号,用来发送邮件
3.准备一个测试用的git repo,此处我提供了 https://github.com/wenboyang214/jenkinsCsharpTest.git
4.运行下列脚本,Jenkins需要设置git、msbuild等的环境变量,请自行设置
三、对邮箱账号本身进行设置(此处以163邮箱为例,其他类似)
Note: Jenkins中配置的邮箱secret需要授权码,而不是密码本身。因此我们需要获取授权码。四、配置Jenkins 的系统参数
[b]你需要做如下截图的配置[/b]
1.最好更改一下Jenkins的Workspace Root Directory,避免符号的一些错误
2.设置Jenkins的System Admin e-mail address,此处的邮箱要和你email notification的邮箱一致
3.在Extended E-mail Notification中进行如下设置,没设置的地方,保持默认
五、测试邮箱提醒功能
1.简单创建一个新的Pipeline item 名称为”test”2.将下列脚本copy到Pipeline script中
#!/usr/bin/env groovy Jenkinsfile pipeline { agent any environment { def gitRepo="https://github.com/wenboyang214/jenkinsCsharpTest.git" def mailRecipients="wenbya@163.com" } stages { stage('1. check the git repo'){ steps{ git "${gitRepo}" } } stage('3. msbuild the project'){ steps{ bat "msbuild .\\JenkinsTest\\JenkinsTest.sln" } } } post { always { echo 'testing email notification' } success { echo 'This will run only if successful' emailext( body: '''${SCRIPT, template="groovy-html.template"}''', mimeType: 'text/html', subject: "[Jenkins]${currentBuild.fullDisplayName}", to: "${mailRecipients}", replyTo: "${mailRecipients}", recipientProviders: [[$class: 'CulpritsRecipientProvider'],[$class: 'DevelopersRecipientProvider']] ) } failure { echo 'This will run only if failed' emailext( body: '''${SCRIPT, template="groovy-html.template"}''', mimeType: 'text/html', subject: "[Jenkins]${currentBuild.fullDisplayName}", to: "${mailRecipients}", replyTo: "${mailRecipients}", recipientProviders: [[$class: 'CulpritsRecipientProvider'],[$class: 'DevelopersRecipientProvider']] ) } unstable { echo 'This will run only if the run was marked as unstable' } changed { echo 'This will run only if the state of the Pipeline has changed' echo 'For example, if the Pipeline was previously failing but is now successful' } } }
直接启动这个test item
六、进行对错改动,并检查邮箱是否收到邮件
更改msbuild的路径,故意让其build出错,检查是否能收到报错邮件。
bat “msbuild .\JenkinsTest\JenkinsTest.sln” => bat “msbuild .\JenkinsTest1\JenkinsTest.sln”
相关文章推荐
- jenkins邮件通知配置和定时设置
- Jenkins 配置邮件通知--内置邮件
- jenkins配置发送邮件报Authentication unsuccessful错误解决方法
- jenkins配置邮件通知功能以及破解管理员密码
- jenkins配置邮件及增强版邮件通知
- jenkins邮件通知的配置
- Jenkins配置邮件通知(四)
- 持续集成&(Jenkins配置发送邮件通知)
- jenkins邮件通知配置
- 【jenkins】之邮件通知配置
- Jenkins 配置邮件通知
- Jenkins通过局域网邮件服务器配置邮件通知(内置邮件系统)
- Jenkins 配置邮件通知
- Jenkins上配置Robot Framework测试邮件通知模板
- Jenkins 配置邮件通知
- jenkins配置QQ邮箱自动发送RF测试构建结果通知邮件
- Jenkins上配置Robot Framework测试邮件通知模板
- Jenkins中使用POP3协议邮件配置
- jenkins 邮件相关配置+破解管理员密码
- Linux服务器下Jenkins+Ant+Tomcat+SVN实现持续集成和部署配置方法