import hudson.model.*; println env.JOB_NAME println env.BUILD_NUMBER pipeline{ agent any stages{ stage("send mail test") { steps{ script { mail to: '1399811201@qq.com', subject: "Running Pipeline: ${currentBuild.fullDisplayName}",1)"> body: "Something is wrong with ${env.BUILD_URL}" } } } } }
pipeline { agent any stages { stage('拉代码') { steps { checkout("svn代码") } } stage(输出日志) { steps { script{ //调用方法得到日志并输出 def changeString = getChangeString() echo $changeString } } } stage(发送邮件) { steps{ script { mail to: qq@qq.com,subject: ${JOB_NAME} (${BUILD_NUMBER})-提交SVN日志信息SVN版本变更信息:\n$changeString\n构建日志: $BUILD_URL/console } } } } } @NonCPS def getChangeString() { MAX_MSG_LEN = 100 def changeString = "" Gathering SCM changes def changeLogSets = currentBuild.changeSets for (int i = 0; i < changeLogSets.size(); i++) { def entries = changeLogSets[i].items int j = 0; j < entries.length; j++) { def entry = entries[j] truncated_msg = entry.msg.take(MAX_MSG_LEN) changeString += ${truncated_msg} -- ${entry.author}\n } } if (!changeString) { changeString = ${currentBuild.fullDisplayName}:当前构建版本没有新的变更信息! } return changeString }
原文链接:/jenkins/992133.html