| 
														
															@@ -1,13 +1,25 @@ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-#!/usr/bin/env groovy 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-import com.example.FeishuNotifier 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+def call(String webhook, String status) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    def info = gatherCommonInfo() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    new com.example.FeishuNotifier(this, webhook).send( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        status, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        env.JOB_NAME, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        env.BUILD_NUMBER, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        info.buildUrl, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        info.duration, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        info.branch, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        info.commitMsg, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        info.author, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        info.commitTime 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    ) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-// 公共采集逻辑 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-@NonCPS 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+// ==========  下面是 CPS 安全的采集逻辑 ========== 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+@com.cloudbees.groovy.cps.NonCPS   // 仅供内部流转,避免返回值被序列化 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 private Map gatherCommonInfo() { 
														 | 
														
														 | 
														
															 private Map gatherCommonInfo() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     def duration = currentBuild.durationString.replace(' and counting', '') 
														 | 
														
														 | 
														
															     def duration = currentBuild.durationString.replace(' and counting', '') 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    def commitMsg  = sh(returnStdout: true, script: "git log -1 --pretty=%B").trim() 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    def author     = sh(returnStdout: true, script: "git log -1 --pretty=%an").trim() 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    def commitTime = sh(returnStdout: true, script: "git log -1 --pretty=%ci").trim() 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    def commitMsg  = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    def author     = sh(returnStdout: true, script: 'git log -1 --pretty=%an').trim() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    def commitTime = sh(returnStdout: true, script: 'git log -1 --pretty=%ci').trim() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     def branch     = env.BRANCH_NAME ?: env.GIT_BRANCH ?: 'unknown' 
														 | 
														
														 | 
														
															     def branch     = env.BRANCH_NAME ?: env.GIT_BRANCH ?: 'unknown' 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     def buildUrl   = env.BUILD_URL.replace('http://68.79.46.88:8080', 'https://jenkins.adwebcloud.com') 
														 | 
														
														 | 
														
															     def buildUrl   = env.BUILD_URL.replace('http://68.79.46.88:8080', 'https://jenkins.adwebcloud.com') 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return [ 
														 | 
														
														 | 
														
															     return [ 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -18,36 +30,4 @@ private Map gatherCommonInfo() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         branch   : branch, 
														 | 
														
														 | 
														
															         branch   : branch, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         buildUrl : buildUrl 
														 | 
														
														 | 
														
															         buildUrl : buildUrl 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     ] 
														 | 
														
														 | 
														
															     ] 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-// 任务开始时调用 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-def start(String webhookUrl) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    def info = gatherCommonInfo() 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    new FeishuNotifier(this, webhookUrl).send( 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        'START',                // 自定义状态 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        env.JOB_NAME, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        env.BUILD_NUMBER, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.buildUrl, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        '0s',                   // 刚开始,持续时间为 0 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.branch, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.commitMsg, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.author, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.commitTime 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    ) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-// 任务结束时调用(就是你现在的 call) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-def call(String webhookUrl, String status) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    def info = gatherCommonInfo() 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    new FeishuNotifier(this, webhookUrl).send( 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        status, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        env.JOB_NAME, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        env.BUILD_NUMBER, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.buildUrl, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.duration, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.branch, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.commitMsg, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.author, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        info.commitTime 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    ) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 |