Commit 6ae3e762 authored by Auto Backup's avatar Auto Backup

feat: 统一命令执行函数,Windows强制使用PowerShell 7 (pwsh)执行

parent f1d01398
......@@ -2,15 +2,16 @@
def runPowerShellWithOutput(script) {
try {
if (isUnix()) {
return sh(script: "pwsh -Command \"${script}\"", returnStdout: true).trim()
// Unix 系统使用 sh 执行命令
return sh(script: "${script}", returnStdout: true).trim()
} else {
return powershell(script: script, returnStdout: true).trim()
// Windows 系统强制使用 PowerShell 7 (pwsh)
return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim()
}
} catch (Exception e) {
echo "执行 PowerShell 脚本失败: ${e.message}"
throw e
}
}
// properties([
......
......@@ -5,15 +5,8 @@ def runCommandWithOutput(script) {
// Unix 系统使用 sh 执行命令
return sh(script: "${script}", returnStdout: true).trim()
} else {
// Windows 系统,尝试多种方式
try {
// 方式1: 尝试使用 powershell 步骤 (需要 PowerShell 插件)
return powershell(script: script, returnStdout: true).trim()
} catch (Exception psError) {
echo "⚠️ PowerShell 步骤失败,尝试使用 bat 命令: ${psError.message}"
// 方式2: 使用 bat 命令执行 PowerShell
return bat(script: "powershell -Command \"${script}\"", returnStdout: true).trim()
}
// Windows 系统强制使用 PowerShell 7 (pwsh)
return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim()
}
} catch (Exception e) {
echo "执行命令失败: ${e.message}"
......
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