From 108a5a34d327561eebdcbd98421f35378252a1ff Mon Sep 17 00:00:00 2001
From: wangzilun <964606955@qq.com>
Date: Wed, 09 Mar 2022 11:05:47 +0800
Subject: [PATCH] ttt3

---
 Jenkinsfile |   60 ++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 3ab4e14..ac43f49 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -20,29 +20,31 @@
     stages {
         stage('source') {
             steps {
-                checkout([$class: 'GitSCM'
-                , branches: [[name: "${GIT_BRANCH}"]]
-                , doGenerateSubmoduleConfigurations: false
-                , extensions: []
-                , submoduleCfg: []
-                , userRemoteConfigs: [[credentialsId: "${GIT_CREDENTIALS_ID}", url: "${url}"]]
-                ])
+                script{
+                    def changeLogSets = checkout([$class: 'GitSCM'
+                                    , branches: [[name: "${GIT_BRANCH}"]]
+                                    , doGenerateSubmoduleConfigurations: false
+                                    , extensions: []
+                                    , submoduleCfg: []
+                                    , userRemoteConfigs: [[credentialsId: "${GIT_CREDENTIALS_ID}", url: "${url}"]]
+                                    ])
+                     println "changeLogSets ${changeLogSets}"
+                     GIT_COMMIT = changeLogSets.get("GIT_COMMIT")
+                     GIT_PREVIOUS_COMMIT = changeLogSets['GIT_PREVIOUS_COMMIT']
+                     env.GIT_COMMIT_AUTHOR = sh (script: 'git log -1 --oneline --pretty=%an ${GIT_COMMIT}', returnStdout: true).trim()
+                     env.GIT_COMMIT_MSG = sh (script: 'git log --oneline --pretty=%s ${GIT_PREVIOUS_COMMIT}...${GIT_COMMIT}| sed = |sed "N;s/\\n/./"', returnStdout: true).trim()
 
+                }
             }
         }
-        stage('testMaven') {
-            steps {
+        //stage('testMaven') {
+            //steps {
 
-                sh 'mvn clean test -U'
-                junit allowEmptyResults: true, keepLongStdio: true, skipPublishingChecks: true, testResults: 'target/surefire-reports/*.xml'
+                //sh 'mvn clean test -U'
+                //junit allowEmptyResults: true, keepLongStdio: true, skipPublishingChecks: true, testResults: 'target/surefire-reports/*.xml'
 
-            }
-        }
-        stage('testFunction') {
-            steps {
-                sh 'echo test'
-            }
-        }
+            //}
+        //}
 
         //将项目打成war并归档,将配置文件目录存入stash
         stage('package') {
@@ -56,17 +58,13 @@
                     old_version_all=\$(cat \$versionFile | sed -nr \'s/^[^0-9]*"([^"]+)".*;/\\1/p\')
                     echo "old_version_all \$old_version_all"
                     echo "project_name \$project_name"
-                    if [["\${old_version_all}" =~ "\$str"]];then
-                        echo "包含"
-                    else
-                        echo "不包含"
-                    fi
                     dir_name=\${project_name}"-"\$old_version_all
                     echo "dir_name \$dir_name"
                     ##cd target
                     ##mkdir \$dir_name
                     ##cp *.war \$dir_name
                     ##zip -r "\$dir_name.zip" \$dir_name
+                    exit 1
                 '''
             }
         }
@@ -83,11 +81,11 @@
             steps {
                 //http(s)的git链接使用帐号密码,ssh使用 keyFileVariable: 'SSH_KEY'
                 echo "todo version add"
-                //versionAddDevelop("${project_name}","${GIT_CREDENTIALS_ID}","${url}","${GIT_BRANCH}")
+                versionAddCom("${project_name}","${GIT_CREDENTIALS_ID}","${url}","${GIT_BRANCH}")
                 }
         }
 
-        stage('version add master') {
+        stage('version add develop') {
             when {
                 //版本号自动添加逻辑需同时符合下列触发条件:
                 //1. 不能在master分支触发
@@ -109,7 +107,7 @@
                 }
             }
             steps {
-                versionAddDevelop("${project_name}","${GIT_CREDENTIALS_ID}","${url}","${GIT_BRANCH}")
+                versionAddCom("${project_name}","${GIT_CREDENTIALS_ID}","${url}","${GIT_BRANCH}")
             }
         }
 
@@ -120,4 +118,14 @@
             }
         }
     }
+
+    post {
+        unsuccessful {
+            script{
+                def msg = "当前构建失败<br>---------------------<br>提交人:${GIT_COMMIT_AUTHOR}<br>提交信息:<br>${GIT_COMMIT_MSG}<br>---------------------<br>构建内网链接:${BUILD_URL}console"
+                def number = "964606955"
+                sendMessage(true,number,msg);
+            }
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1