luhaowen 5 days ago
parent
commit
c44f15ca49
4 changed files with 49 additions and 15 deletions
  1. 46 15
      src/com/example/FeishuNotifier.groovy
  2. 1 0
      vars/feishuNotify.groovy
  3. 1 0
      vars/feishuStart.groovy
  4. 1 0
      vars/gatherInfo.groovy

+ 46 - 15
src/com/example/FeishuNotifier.groovy

@@ -15,25 +15,56 @@ class FeishuNotifier implements Serializable {
               String duration, String branch, String commitMsg, String author,
               String commitTime) {
 
-        // 根据状态决定标题颜色
-        def title = (status == 'START') ? '🔵 构建开始' :
+        // 1. 决定左侧条颜色 + 标题
+        def color = (status == 'START')  ? 'blue' :
+                    (status == 'SUCCESS') ? 'green' :
+                    (status == 'FAILURE') ? 'red' : 'yellow'
+        def title = (status == 'START')  ? '🔵 构建开始' :
                     (status == 'SUCCESS') ? '✅ 构建成功' :
                     (status == 'FAILURE') ? '❌ 构建失败' : '🟡 构建不稳定'
 
+        // 2. 飞书极简卡片:header + elements
         def payload = [
-            msg_type: 'text',
-            content: [
-                text: """
-                ${title}
-                任务名称: ${jobName}
-                构建编号: #${buildNumber}
-                持续时间: ${duration}
-                分支: ${branch}
-                提交: ${commitMsg}
-                作者: ${author}
-                提交时间: ${commitTime}
-                查看详情: ${buildUrl}
-                """.stripIndent()
+            msg_type: 'interactive',
+            card: [
+                header: [
+                    title: [
+                        tag: 'plain_text',
+                        content: title
+                    ],
+                    template: color   // 左侧条颜色
+                ],
+                elements: [
+                    [
+                        tag: 'div',
+                        text: [
+                            tag: 'lark_md',
+                            content: """
+**任务名称**: ${jobName}  
+**构建编号**: [#${buildNumber}](${buildUrl})  
+**持续时间**: ${duration}  
+**分支**: ${branch}  
+**提交信息**: ${commitMsg}  
+**作者**: ${author}  
+**提交时间**: ${commitTime}
+""".stripIndent()
+                        ]
+                    ],
+                    [
+                        tag: 'action',
+                        actions: [
+                            [
+                                tag: 'button',
+                                text: [
+                                    tag: 'plain_text',
+                                    content: '查看详情'
+                                ],
+                                type: 'primary',
+                                url: buildUrl
+                            ]
+                        ]
+                    ]
+                ]
             ]
         ]
 

+ 1 - 0
vars/feishuNotify.groovy

@@ -1,3 +1,4 @@
+// var/feishuNotify.groovy
 def call(String webhook, String status, String branch = null) {
     def info = gatherInfo(branch)          // 把分支传进去
     new com.example.FeishuNotifier(this, webhook).send(

+ 1 - 0
vars/feishuStart.groovy

@@ -1,3 +1,4 @@
+// vars/feishuStart.groovy 
 def call(String webhook, String branch = null) {
     def info = gatherInfo(branch)          // 把分支传进去
     new com.example.FeishuNotifier(this, webhook).send(

+ 1 - 0
vars/gatherInfo.groovy

@@ -1,3 +1,4 @@
+// vars/gatherInfo.groovy   
 def call(String branchOverride = null) {
     def duration = currentBuild.durationString.replace(' and counting', '')
     def commitMsg  = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()