Commit 680ef948 authored by Auto Backup's avatar Auto Backup

feat: utf8

parent e5ace154
......@@ -2,23 +2,36 @@
def runPowerShellWithOutput(script) {
try {
if (isUnix()) {
// Unix 系统使用 sh 执行命令
return sh(script: "${script}", returnStdout: true).trim()
} else {
// Windows 系统优先使用 PowerShell 7 (pwsh),失败时回退到 PowerShell 5
// 核心逻辑:先切换 CMD 代码页到 65001 (UTF-8),再强制 PowerShell 输出编码
// 使用 @echo off 隐藏 chcp 的输出,只返回 script 的结果
def utf8Wrapper = """
@echo off
chcp 65001 > nul
powershell -NoProfile -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${script}"
""".trim()
// 同样的逻辑,优先尝试 pwsh (PowerShell 7)
try {
return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim()
def pwshWrapper = """
@echo off
chcp 65001 > nul
pwsh -NoProfile -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${script}"
""".trim()
return bat(script: pwshWrapper, returnStdout: true).trim()
} catch (Exception pwshError) {
echo "⚠️ PowerShell 7 (pwsh) 执行失败,尝试使用 PowerShell 5: ${pwshError.message}"
return bat(script: "powershell -NoProfile -Command \"${script}\"", returnStdout: true).trim()
echo "⚠️ pwsh 执行失败,回退到 powershell 5: ${pwshError.message}"
return bat(script: utf8Wrapper, returnStdout: true).trim()
}
}
} catch (Exception e) {
echo "执行 PowerShell 脚本失败: ${e.message}"
echo "执行脚本失败: ${e.message}"
throw e
}
}
/**
* 执行 Git log 命令,自动处理跨平台 % 转义问题
* @param format Git 的 --pretty 格式字符串(如 %an, %B, %ae)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment