luhaowen преди 1 седмица
родител
ревизия
9acf5d20fe
променени са 2 файла, в които са добавени 11 реда и са изтрити 13 реда
  1. 4 5
      vars/feishu.groovy
  2. 7 8
      vars/onBuildEvent.groovy

+ 4 - 5
vars/feishu.groovy

@@ -2,13 +2,12 @@
 import groovy.json.JsonOutput
 
 def send(String webhook, Map card) {
-    // webhook 必须是纯字符串,不能再出现 credentials()
     httpRequest(
         httpMode: 'POST',
-        requestBody: JsonOutput.toJson([msg_type: 'interactive', card: card]),
+        url: webhook,
         contentType: 'APPLICATION_JSON',
-        url: webhook,                      // 这里一定是合法 URL
-        consoleLogResponseBody: true,
-        validResponseCodes: '200'
+        requestBody: JsonOutput.toJson([msg_type: 'interactive', card: card]),
+        validResponseCodes: '200',
+        consoleLogResponseBody: true
     )
 }

+ 7 - 8
vars/onBuildEvent.groovy

@@ -1,22 +1,21 @@
 #!/usr/bin/env groovy
 def call(String phase) {
-    // 先读凭据
+    // 1. 先把凭据解析成真正的 URL 字符串
     String webhook = credentials('feishu-webhook')
 
-    // 组装卡片(同上,略)
-    String jobName = env.JOB_NAME
+    // 2. 取环境变量
+    String jobName  = env.JOB_NAME
     String buildNum = env.BUILD_NUMBER
-    String branch  = env.GIT_BRANCH ?: 'unknown'
-    String result  = currentBuild.currentResult ?: 'UNKNOWN'
+    String branch   = env.GIT_BRANCH ?: 'unknown'
+    String result   = currentBuild.currentResult ?: 'UNKNOWN'
     String buildUrl = env.BUILD_URL
     String duration = phase == 'end' ? "${currentBuild.durationString}" : '-'
 
     String headerColor = phase == 'start' ? 'blue' : (result == 'SUCCESS' ? 'green' : 'red')
-    String headerIcon  = phase == 'start' ? 'rocket' : (result == 'SUCCESS' ? 'check_circle' : 'error')
 
     def card = [
         header: [
-            title: [ tag: "plain_text", content: "Jenkins ${phase == 'start' ? '开始' : '结束'}通知" ],
+            title: [tag: "plain_text", content: "Jenkins ${phase == 'start' ? '开始' : '结束'}通知"],
             template: headerColor
         ],
         elements: [
@@ -35,6 +34,6 @@ def call(String phase) {
         ]
     ]
 
-    // 把真正的 url 传进去
+    // 3. 发送
     feishu.send(webhook, card)
 }