Quellcode durchsuchen

Initial commit2

luhaowen vor 1 Woche
Ursprung
Commit
4ce309f541
2 geänderte Dateien mit 10 neuen und 17 gelöschten Zeilen
  1. 2 2
      vars/feishu.groovy
  2. 8 15
      vars/onBuildEvent.groovy

+ 2 - 2
vars/feishu.groovy

@@ -2,12 +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]),
         contentType: 'APPLICATION_JSON',
-        url: webhook,
+        url: webhook,                      // 这里一定是合法 URL
         consoleLogResponseBody: true,
         validResponseCodes: '200'
     )

+ 8 - 15
vars/onBuildEvent.groovy

@@ -1,28 +1,22 @@
 #!/usr/bin/env groovy
-/**
- * 在 pipeline 的开始 & 结束各调用一次即可:
- * onBuildEvent('start')
- * onBuildEvent('end')
- */
 def call(String phase) {
-    // 从 Jenkins 环境变量里取值
+    // 先读凭据
+    String webhook = credentials('feishu-webhook')
+
+    // 组装卡片(同上,略)
     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: [
@@ -41,7 +35,6 @@ def call(String phase) {
         ]
     ]
 
-    // 只读取 webhook 凭据,不处理 secret
-    String webhook = credentials('feishu-webhook')
+    // 把真正的 url 传进去
     feishu.send(webhook, card)
 }