feishuNotify.groovy 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. def call(String webhook, String status) {
  2. def info = gatherCommonInfo()
  3. new com.example.FeishuNotifier(this, webhook).send(
  4. status,
  5. env.JOB_NAME,
  6. env.BUILD_NUMBER,
  7. info.buildUrl,
  8. info.duration,
  9. info.branch,
  10. info.commitMsg,
  11. info.author,
  12. info.commitTime
  13. )
  14. }
  15. // ========== 下面是 CPS 安全的采集逻辑 ==========
  16. @com.cloudbees.groovy.cps.NonCPS // 仅供内部流转,避免返回值被序列化
  17. private Map gatherCommonInfo() {
  18. def duration = currentBuild.durationString.replace(' and counting', '')
  19. def commitMsg = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()
  20. def author = sh(returnStdout: true, script: 'git log -1 --pretty=%an').trim()
  21. def commitTime = sh(returnStdout: true, script: 'git log -1 --pretty=%ci').trim()
  22. def branch = env.BRANCH_NAME ?: env.GIT_BRANCH ?: 'unknown'
  23. def buildUrl = env.BUILD_URL.replace('http://68.79.46.88:8080', 'https://jenkins.adwebcloud.com')
  24. return [
  25. duration : duration,
  26. commitMsg: commitMsg,
  27. author : author,
  28. commitTime: commitTime,
  29. branch : branch,
  30. buildUrl : buildUrl
  31. ]
  32. }