Commit adf6cd49 authored by Auto Backup's avatar Auto Backup

feat: 增强命令执行函数,优先使用PowerShell 7,失败时回退到PowerShell 5

parent 6ae3e762
...@@ -5,8 +5,13 @@ def runPowerShellWithOutput(script) { ...@@ -5,8 +5,13 @@ def runPowerShellWithOutput(script) {
// Unix 系统使用 sh 执行命令 // Unix 系统使用 sh 执行命令
return sh(script: "${script}", returnStdout: true).trim() return sh(script: "${script}", returnStdout: true).trim()
} else { } else {
// Windows 系统强制使用 PowerShell 7 (pwsh) // Windows 系统优先使用 PowerShell 7 (pwsh),失败时回退到 PowerShell 5
try {
return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim() return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim()
} catch (Exception pwshError) {
echo "⚠️ PowerShell 7 (pwsh) 执行失败,尝试使用 PowerShell 5: ${pwshError.message}"
return bat(script: "powershell -NoProfile -Command \"${script}\"", returnStdout: true).trim()
}
} }
} catch (Exception e) { } catch (Exception e) {
echo "执行 PowerShell 脚本失败: ${e.message}" echo "执行 PowerShell 脚本失败: ${e.message}"
......
...@@ -5,8 +5,13 @@ def runCommandWithOutput(script) { ...@@ -5,8 +5,13 @@ def runCommandWithOutput(script) {
// Unix 系统使用 sh 执行命令 // Unix 系统使用 sh 执行命令
return sh(script: "${script}", returnStdout: true).trim() return sh(script: "${script}", returnStdout: true).trim()
} else { } else {
// Windows 系统强制使用 PowerShell 7 (pwsh) // Windows 系统优先使用 PowerShell 7 (pwsh),失败时回退到 PowerShell 5
try {
return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim() return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim()
} catch (Exception pwshError) {
echo "⚠️ PowerShell 7 (pwsh) 执行失败,尝试使用 PowerShell 5: ${pwshError.message}"
return bat(script: "powershell -NoProfile -Command \"${script}\"", returnStdout: true).trim()
}
} }
} catch (Exception e) { } catch (Exception e) {
echo "执行命令失败: ${e.message}" 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