feishuNotify.groovy 974 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env groovy
  2. import com.example.FeishuNotifier
  3. def call(String webhookUrl, String status) {
  4. // 1. 采集常规信息
  5. def duration = currentBuild.durationString.replace(' and counting', '')
  6. def commitMsg = sh(returnStdout: true, script: "git log -1 --pretty=%B").trim()
  7. def author = sh(returnStdout: true, script: "git log -1 --pretty=%an").trim()
  8. def commitTime = sh(returnStdout: true, script: "git log -1 --pretty=%ci").trim()
  9. def branch = env.brach ?: env.GIT_BRANCH ?: env.BRANCH_NAME ?: 'unknown'
  10. // 2. 把原始 BUILD_URL 改成走 Nginx 代理的 https 域名
  11. def buildUrl = env.BUILD_URL.replace('http://68.79.46.88:8080', 'https://jenkins.adwebcloud.com')
  12. // 3. 发送飞书消息
  13. new FeishuNotifier(this, webhookUrl).send(
  14. status,
  15. env.JOB_NAME,
  16. env.BUILD_NUMBER,
  17. buildUrl,
  18. duration,
  19. branch,
  20. commitMsg,
  21. author,
  22. commitTime
  23. )
  24. }