From 0dd1cb297c8841974c20c503e52f4e155a172115 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 23 May 2026 01:34:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ci):=20=E7=A7=BB=E9=99=A4=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=89=88=E6=9C=AC=E5=8F=B7=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E4=BB=85=E4=BF=9D=E7=95=99=E8=87=AA=E5=8A=A8=E5=8D=87?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 110 +++++++++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 70 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5129514..2cb353e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,16 +5,6 @@ pipeline { // ── 版本升级策略 ───────────────────────────────────────────────────── choice(name: 'VERSION_BUMP', choices: ['patch', 'minor', 'major'], description: '版本升级策略: major(1.0.0→2.0.0), minor(1.0.0→1.1.0), patch(1.0.0→1.0.1)') - booleanParam(name: 'CUSTOM_VERSION', defaultValue: false, - description: '勾选后使用下方自定义版本号(忽略VERSION_BUMP)') - - // 模块自定义版本号(仅CUSTOM_VERSION=true时生效) - string(name: 'CORE_VERSION', defaultValue: '', description: 'sdk-core 自定义版本号(仅CUSTOM_VERSION=true时生效)') - string(name: 'IM_VERSION', defaultValue: '', description: 'sdk-im 自定义版本号') - string(name: 'PUSH_VERSION', defaultValue: '', description: 'sdk-push 自定义版本号') - string(name: 'UPDATE_VERSION', defaultValue: '', description: 'sdk-update 自定义版本号') - string(name: 'WEBVIEW_VERSION', defaultValue: '', description: 'sdk-webview 自定义版本号') - string(name: 'LICENSE_VERSION', defaultValue: '', description: 'sdk-license 自定义版本号') // 要构建并发布的模块(勾选即发布) booleanParam(name: 'MOD_CORE', defaultValue: true, description: '发布 sdk-core') @@ -42,21 +32,6 @@ pipeline { userRemoteConfigs: scm.userRemoteConfigs ]) script { - // 构建 -P 参数字符串 - def versionMap = [ - 'SDK_CORE_VERSION' : params.CORE_VERSION?.trim(), - 'SDK_IM_VERSION' : params.IM_VERSION?.trim(), - 'SDK_PUSH_VERSION' : params.PUSH_VERSION?.trim(), - 'SDK_UPDATE_VERSION' : params.UPDATE_VERSION?.trim(), - 'SDK_WEBVIEW_VERSION' : params.WEBVIEW_VERSION?.trim(), - 'SDK_LICENSE_VERSION' : params.LICENSE_VERSION?.trim(), - ] - - env.VERSION_ARGS = versionMap - .findAll { k, v -> v } - .collect { k, v -> "-P${k}=${v}" } - .join(' ') - // 根据复选框收集要发布的模块 def moduleChecks = [ 'sdk-core': params.MOD_CORE, @@ -71,11 +46,8 @@ pipeline { error("没有选择任何模块,请至少勾选一个") } - // 保存为逗号分隔的环境变量供后续阶段使用 env.PUBLISH_MODULES = resolved.join(',') - - echo "Version args : ${env.VERSION_ARGS ?: '(none — using gradle.properties values)'}" - echo "Modules : ${env.PUBLISH_MODULES}" + echo "Modules: ${env.PUBLISH_MODULES}" } } } @@ -83,49 +55,47 @@ pipeline { stage('Resolve Versions') { steps { script { - if (!params.CUSTOM_VERSION) { - // 从 gradle.properties 读取当前版本号 - def currentVer = bat( - script: "@powershell -Command \"(Get-Content gradle.properties | Select-String '^PUBLISH_VERSION=').Line.Split('=')[1]\"", - returnStdout: true - ).trim() - echo "Current PUBLISH_VERSION: ${currentVer}" + // 从 gradle.properties 读取当前版本号 + def currentVer = bat( + script: "@powershell -Command \"(Get-Content gradle.properties | Select-String '^PUBLISH_VERSION=').Line.Split('=')[1]\"", + returnStdout: true + ).trim() + echo "Current PUBLISH_VERSION: ${currentVer}" - def parts = currentVer.tokenize('.') - while (parts.size() < 3) { parts.add('0') } - switch (params.VERSION_BUMP) { - case 'major': - parts[0] = (parts[0].toInteger() + 1).toString() - parts[1] = '0' - parts[2] = '0' - break - case 'minor': - parts[1] = (parts[1].toInteger() + 1).toString() - parts[2] = '0' - break - case 'patch': - default: - parts[2] = (parts[2].toInteger() + 1).toString() - break - } - def newVer = parts.join('.') - echo "Auto-bumped PUBLISH_VERSION: ${currentVer} → ${newVer}" - - // 更新 gradle.properties - bat "powershell -Command \"(Get-Content gradle.properties) -replace '^PUBLISH_VERSION=.*', 'PUBLISH_VERSION=${newVer}' | Set-Content gradle.properties\"" - - // 用新版本号重建所有模块的 VERSION_ARGS - def modules = env.PUBLISH_MODULES.split(',').toList() - def versionMap = [:] - for (mod in modules) { - def propName = "SDK_${mod.replace('sdk-', '').toUpperCase()}_VERSION" - versionMap[propName] = newVer - } - env.VERSION_ARGS = versionMap - .collect { k, v -> "-P${k}=${v}" } - .join(' ') - echo "Updated VERSION_ARGS: ${env.VERSION_ARGS}" + def parts = currentVer.tokenize('.') + while (parts.size() < 3) { parts.add('0') } + switch (params.VERSION_BUMP) { + case 'major': + parts[0] = (parts[0].toInteger() + 1).toString() + parts[1] = '0' + parts[2] = '0' + break + case 'minor': + parts[1] = (parts[1].toInteger() + 1).toString() + parts[2] = '0' + break + case 'patch': + default: + parts[2] = (parts[2].toInteger() + 1).toString() + break } + def newVer = parts.join('.') + echo "Auto-bumped PUBLISH_VERSION: ${currentVer} → ${newVer}" + + // 更新 gradle.properties + bat "powershell -Command \"(Get-Content gradle.properties) -replace '^PUBLISH_VERSION=.*', 'PUBLISH_VERSION=${newVer}' | Set-Content gradle.properties\"" + + // 用新版本号设置所有模块的版本参数 + def modules = env.PUBLISH_MODULES.split(',').toList() + def versionMap = [:] + for (mod in modules) { + def propName = "SDK_${mod.replace('sdk-', '').toUpperCase()}_VERSION" + versionMap[propName] = newVer + } + env.VERSION_ARGS = versionMap + .collect { k, v -> "-P${k}=${v}" } + .join(' ') + echo "VERSION_ARGS: ${env.VERSION_ARGS}" } } }