| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package com.example
- import groovy.json.JsonOutput
- import jenkins.model.Jenkins
- class FeishuNotifier implements Serializable {
- def script
- String webhookUrl
- FeishuNotifier(script, String webhookUrl) {
- this.script = script
- this.webhookUrl = webhookUrl
- }
- void send(String status, String jobName, String buildNumber, String buildUrl, String duration) {
- def colorMap = [
- 'SUCCESS': 'green',
- 'FAILURE': 'red',
- 'UNSTABLE': 'yellow',
- 'ABORTED': 'gray'
- ]
- def title = "Jenkins构建通知"
- def text = """
- 🚀 **构建状态**: ${status}\n
- 📦 **任务名称**: ${jobName}\n
- 🔢 **构建编号**: #${buildNumber}\n
- ⏱️ **持续时间**: ${duration}\n
- 🔗 [点击查看详情](${buildUrl})
- """.stripIndent()
- def payload = [
- msg_type: "post",
- content: [
- post: [
- zh_cn: [
- title: title,
- content: [[ tag: "text", text: text ]]
- ]
- ]
- ]
- ]
- script.httpRequest(
- url: webhookUrl,
- httpMode: 'POST',
- requestBody: JsonOutput.toJson(payload),
- contentType: 'APPLICATION_JSON',
- consoleLogResponseBody: true
- )
- }
- }
|