jenkins流水线pipeline脚本实例
发送邮件
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}", body: "Something is wrong with ${env.BUILD_URL}" } } } } }
发送邮件svn日志内容
pipeline { agent any stages { stage('拉代码') { steps { checkout("svn代码") } } stage('输出日志') { steps { script{ //调用方法得到日志并输出 def changeString = getChangeString() echo "$changeString" } } } stage("发送邮件") { steps{ script { echo "$changeString" mail to: 'qq@qq.com', subject: "${JOB_NAME} (${BUILD_NUMBER})-提交SVN日志信息", body: "SVN版本变更信息:\n$changeString\n构建日志: $BUILD_URL/console" } } } } } @NonCPS def getChangeString() { MAX_MSG_LEN = 100 def changeString = "" echo "Gathering SCM changes" def changeLogSets = currentBuild.changeSets for (int i = 0; i < changeLogSets.size(); i++) { def entries = changeLogSets[i].items for (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 }
优秀不够,你是否无可替代
软件测试交流QQ群:721256703,期待你的加入!!
欢迎关注我的微信公众号:软件测试君
![](https://www.cnblogs.com/images/cnblogs_com/longronglang/1061549/o_QQ%E6%88%AA%E5%9B%BE20190728134401.jpg)