FeishuNotifier.groovy 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.example
  2. import groovy.json.JsonOutput
  3. class FeishuNotifier implements Serializable {
  4. def script
  5. String webhookUrl
  6. FeishuNotifier(script, String webhookUrl) {
  7. this.script = script
  8. this.webhookUrl = webhookUrl
  9. }
  10. void send(String status, String jobName, String buildNumber, String buildUrl,
  11. String duration, String branch, String commitMsg, String author,
  12. String commitTime) { // 新增参数
  13. def payload = [
  14. msg_type: 'text',
  15. content: [
  16. text: """
  17. 构建状态: ${status}
  18. 任务名称: ${jobName}
  19. 构建编号: #${buildNumber}
  20. 持续时间: ${duration}
  21. 分支: ${branch}
  22. 提交: ${commitMsg}
  23. 作者: ${author}
  24. 提交时间: ${commitTime} // 新增
  25. 查看详情: ${buildUrl}
  26. """.stripIndent()
  27. ]
  28. ]
  29. def jsonBody = JsonOutput.toJson(payload)
  30. script.println ">>> Feishu JSON: ${jsonBody}"
  31. script.httpRequest(
  32. url : webhookUrl,
  33. httpMode : 'POST',
  34. requestBody: jsonBody,
  35. contentType: 'APPLICATION_JSON',
  36. consoleLogResponseBody: true
  37. )
  38. }
  39. }