luhaowen 5 days ago
parent
commit
c572ec200a
3 changed files with 12 additions and 8 deletions
  1. 2 2
      vars/feishuNotify.groovy
  2. 2 2
      vars/feishuStart.groovy
  3. 8 4
      vars/gatherInfo.groovy

+ 2 - 2
vars/feishuNotify.groovy

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

+ 2 - 2
vars/feishuStart.groovy

@@ -1,5 +1,5 @@
-def call(String webhook) {
-    def info = gatherInfo()
+def call(String webhook, String branch = null) {
+    def info = gatherInfo(branch)          // 把分支传进去
     new com.example.FeishuNotifier(this, webhook).send(
         'START',
         env.JOB_NAME,

+ 8 - 4
vars/gatherInfo.groovy

@@ -1,11 +1,15 @@
-// vars/gatherInfo.groovy
-def call() {
+def call(String branchOverride = null) {
     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 branch     = env.BRANCH_NAME ?: env.GIT_BRANCH ?: 'unknown'
-    def buildUrl   = env.BUILD_URL.replace('http://68.79.46.88:8080', 'https://jenkins.adwebcloud.com')
+
+    // 优先级:外部传入 > GIT_BRANCH > BRANCH_NAME > unknown
+    def branch = branchOverride ?: env.GIT_BRANCH ?: env.BRANCH_NAME ?: 'unknown'
+
+    // 去掉多余空格
+    def buildUrl = env.BUILD_URL.replace('http://68.79.46.88:8080', 'https://jenkins.adwebcloud.com')
+
     return [
         duration : duration,
         commitMsg: commitMsg,