|
|
@@ -41,11 +41,21 @@ def call(Map args = [:]) {
|
|
|
"""
|
|
|
|
|
|
/* 3. 传包 + MD5 强校验 */
|
|
|
+ // 1. 在本地计算 MD5
|
|
|
String localMd5 = sh(script: "md5sum ${jarPath} | awk '{print \$1}'", returnStdout: true).trim()
|
|
|
+
|
|
|
+ // 2. 传输 JAR 包
|
|
|
sh "scp -o StrictHostKeyChecking=no ${jarPath} ${remoteHost}:${remoteJar}"
|
|
|
-
|
|
|
- // ❌ 修复点:修改 awk 脚本的转义方式,使用单引号包裹,并让 Groovy 正确输出 \$1
|
|
|
- String remoteMd5 = sh(script: "ssh -o StrictHostKeyChecking=no ${remoteHost} 'md5sum ${remoteJar} | awk \\'{print \\\$1}\\' '", returnStdout: true).trim()
|
|
|
+
|
|
|
+ // 3. 远程计算 MD5 并返回(Jenkins Pipeline 会自动修剪输出)
|
|
|
+ String remoteMd5Output = sh(
|
|
|
+ script: "ssh -o StrictHostKeyChecking=no ${remoteHost} 'md5sum ${remoteJar}'",
|
|
|
+ returnStdout: true
|
|
|
+ ).trim()
|
|
|
+
|
|
|
+ // 4. 在 Jenkins Groovy 侧处理输出,提取 MD5 值
|
|
|
+ // 输出格式通常是 "MD5_SUM FILENAME"。我们只需要第一个字段。
|
|
|
+ String remoteMd5 = remoteMd5Output.split('\\s+')[0]
|
|
|
|
|
|
if (localMd5 != remoteMd5) {
|
|
|
error("MD5 校验失败:本地 ${localMd5} != 远程 ${remoteMd5}")
|