Note: Jenkins中配置的邮箱secret须要受权码,而不是密码自己。所以咱们须要获取受权码。html
你须要作以下截图的配置git
#!/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 itemgithub
更改msbuild的路径,故意让其build出错,检查是否能收到报错邮件。windows
bat “msbuild .\JenkinsTest\JenkinsTest.sln” => bat “msbuild .\JenkinsTest1\JenkinsTest.sln”