From 883a623505c8178cedbc2033d7891d05fc6c68d1 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 23 May 2026 02:01:14 +0800 Subject: [PATCH] fix(ci): explicit ASCII encoding for version read, git checkout main - Force ASCII output encoding in PowerShell to avoid hidden chars - Add git checkout main before commit to avoid detached HEAD - Simplify version reading command Co-Authored-By: Claude Opus 4.7 --- Jenkinsfile | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fe287f8..bca8c98 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -50,36 +50,31 @@ pipeline { stage('Resolve Versions') { steps { script { - // Read version using Groovy to avoid PowerShell encoding issues - def props = readProperties file: 'gradle.properties' - def currentVer = props['PUBLISH_VERSION'] ?: '0.1.0' + // Read version using powershell with explicit encoding + def verLine = bat( + script: '@powershell -NoProfile -Command "[Console]::OutputEncoding=[Text.Encoding]::ASCII; (Get-Content gradle.properties | Select-String \'PUBLISH_VERSION\').ToString().Split(\'=\')[1].Trim()"', + returnStdout: true + ).trim() + def currentVer = verLine ?: '0.1.0' echo "Current PUBLISH_VERSION: ${currentVer}" def parts = currentVer.tokenize('.') while (parts.size() < 3) { parts.add('0') } + def major = parts[0].toInteger() + def minor = parts[1].toInteger() + def patch = parts[2].toInteger() + 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 + case 'major': major++; minor = 0; patch = 0; break + case 'minor': minor++; patch = 0; break + case 'patch': default: patch++; break } - def newVer = parts.join('.') + def newVer = "${major}.${minor}.${patch}" echo "Auto-bumped PUBLISH_VERSION: ${currentVer} → ${newVer}" env.NEW_VERSION = newVer - // Write back using Groovy to avoid PowerShell encoding issues - def content = readFile('gradle.properties') - content = content.replaceAll(/(?m)^PUBLISH_VERSION=.*/, "PUBLISH_VERSION=${newVer}") - writeFile file: 'gradle.properties', text: content + // Write back using powershell + bat "powershell -Command \"(Get-Content gradle.properties) -replace '^PUBLISH_VERSION=.*', 'PUBLISH_VERSION=${newVer}' | Set-Content -NoNewline gradle.properties\"" def modules = env.PUBLISH_MODULES.split(',').toList() def versionMap = [:] @@ -120,6 +115,7 @@ pipeline { steps { script { bat """ + git checkout main git config user.email "jenkins@xuqm.com" git config user.name "Jenkins CI" git add gradle.properties