jenkins流水线pipeline脚本实例

前端之家收集整理的这篇文章主要介绍了jenkins流水线pipeline脚本实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

发送邮件

  1. import hudson.model.*;
  2. println env.JOB_NAME
  3. println env.BUILD_NUMBER
  4. pipeline{
  5. agent any
  6. stages{
  7. stage("send mail test") {
  8. steps{
  9. script {
  10. mail to: '1399811201@qq.com',
  11. subject: "Running Pipeline: ${currentBuild.fullDisplayName}",1)">
  12. body: "Something is wrong with ${env.BUILD_URL}"
  13. }
  14. }
  15. }
  16. }
  17. }

发送邮件svn日志内容

  1. pipeline {
  2. agent any
  3. stages {
  4. stage('代码') {
  5. steps {
  6. checkout("svn代码")
  7. }
  8. }
  9. stage(输出日志) {
  10. steps {
  11. script{
  12. //调用方法得到日志并输出
  13. def changeString = getChangeString()
  14. echo $changeString
  15. }
  16. }
  17. }
  18. stage(发送邮件) {
  19. steps{
  20. script {
  21. mail to: qq@qq.com,subject: ${JOB_NAME} (${BUILD_NUMBER})-提交SVN日志信息SVN版本变更信息:\n$changeString\n构建日志: $BUILD_URL/console
  22. }
  23. }
  24. }
  25. }
  26. }
  27. @NonCPS
  28. def getChangeString() {
  29. MAX_MSG_LEN = 100
  30. def changeString = ""
  31. Gathering SCM changes
  32. def changeLogSets = currentBuild.changeSets
  33. for (int i = 0; i < changeLogSets.size(); i++) {
  34. def entries = changeLogSets[i].items
  35. int j = 0; j < entries.length; j++) {
  36. def entry = entries[j]
  37. truncated_msg = entry.msg.take(MAX_MSG_LEN)
  38. changeString += ${truncated_msg} -- ${entry.author}\n
  39. }
  40. }
  41. if (!changeString) {
  42. changeString = ${currentBuild.fullDisplayName}:当前构建版本没有新的变更信息!
  43. }
  44. return changeString
  45. }

 

猜你在找的Jenkins相关文章