luhaowen 2 veckor sedan
förälder
incheckning
96a89be87f
1 ändrade filer med 27 tillägg och 26 borttagningar
  1. 27 26
      vars/deployJar.groovy

+ 27 - 26
vars/deployJar.groovy

@@ -1,31 +1,32 @@
-#!/usr/bin/env groovy
-def call(Map args = [:]) {
-    String jarName    = args.jarName    ?: env.JAR_NAME
-    String jarPath    = args.jarPath    ?: env.JAR_PATH
-    String remoteHost = args.remoteHost ?: env.REMOTE_HOST
-    String remotePort = args.remotePort ?: env.REMOTE_PORT
-    String remotePath = args.remotePath ?: env.REMOTE_PATH
-    String profile    = args.profile    ?: env.profile
-    String remoteJar  = "${remotePath}/${jarName}"
+    #!/usr/bin/env groovy
+    def call(Map args = [:]) {
+        String jarName    = args.jarName    ?: env.JAR_NAME
+        String jarPath    = args.jarPath    ?: env.JAR_PATH
+        String remoteHost = args.remoteHost ?: env.REMOTE_HOST
+        String remotePort = args.remotePort ?: env.REMOTE_PORT
+        String remotePath = args.remotePath ?: env.REMOTE_PATH
+        String profile    = args.profile    ?: env.profile
+        String remoteJar  = "${remotePath}/${jarName}"
+        String jvmArgs = args.jvmArgs ?: env.JVM_ARGS ?: ''
+        
+        PrintMes("开始发布 ${jarName} 到 ${remoteHost}:${remotePort}", 'yellow')
 
-    PrintMes("开始发布 ${jarName} 到 ${remoteHost}:${remotePort}", 'yellow')
+        try {
+            /* 1. 停旧服务 */
+            sh "ssh -o StrictHostKeyChecking=no ${remoteHost} 'lsof -ti:${remotePort} | xargs -r kill -9 || true'"
 
-    try {
-        /* 1. 停旧服务 */
-        sh "ssh -o StrictHostKeyChecking=no ${remoteHost} 'lsof -ti:${remotePort} | xargs -r kill -9 || true'"
+            /* 2. 备份旧包 */
+            sh "ssh -o StrictHostKeyChecking=no ${remoteHost} 'test -f ${remoteJar} && mv ${remoteJar} ${remoteJar}-\$(date +%Y%m%d%H%M) || true'"
 
-        /* 2. 备份旧包 */
-        sh "ssh -o StrictHostKeyChecking=no ${remoteHost} 'test -f ${remoteJar} && mv ${remoteJar} ${remoteJar}-\$(date +%Y%m%d%H%M) || true'"
+            /* 3. 传新包 */
+            sh "scp -o StrictHostKeyChecking=no ${jarPath} ${remoteHost}:${remoteJar}"
 
-        /* 3. 传新包 */
-        sh "scp -o StrictHostKeyChecking=no ${jarPath} ${remoteHost}:${remoteJar}"
+            /* 4. 启动新服务 */
+            sh """ssh -o StrictHostKeyChecking=no ${remoteHost} "sh -c 'cd ${remotePath} && nohup java ${jvmArgs} -jar ${jarName} --spring.profiles.active=${profile} > server.log 2>&1 &'" """
 
-        /* 4. 启动新服务 */
-        sh """ssh -o StrictHostKeyChecking=no ${remoteHost} "sh -c 'cd ${remotePath} && nohup java -jar ${jarName} --spring.profiles.active=${profile} > server.log 2>&1 &'" """
-
-        PrintMes("发布成功 ${jarName}", 'green')
-    } catch (Exception e) {
-        PrintMes("发布失败 ${jarName} : ${e.message}", 'red')
-        error('deploySpringBoot failed')
-    }
-}
+            PrintMes("发布成功 ${jarName}", 'green')
+        } catch (Exception e) {
+            PrintMes("发布失败 ${jarName} : ${e.message}", 'red')
+            error('deploySpringBoot failed')
+        }
+    }