Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
cpas6-install
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李金钢
cpas6-install
Commits
adf6cd49
Commit
adf6cd49
authored
Mar 19, 2026
by
Auto Backup
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增强命令执行函数,优先使用PowerShell 7,失败时回退到PowerShell 5
parent
6ae3e762
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
Jenkinsfile
Jenkinsfile
+7
-2
environment-check.Jenkinsfile
environment-check.Jenkinsfile
+7
-2
No files found.
Jenkinsfile
View file @
adf6cd49
...
@@ -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
return
bat
(
script:
"pwsh -NoProfile -Command \"${script}\""
,
returnStdout:
true
).
trim
()
try
{
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}"
...
...
environment-check.Jenkinsfile
View file @
adf6cd49
...
@@ -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
return bat(script: "pwsh -NoProfile -Command \"${script}\"", returnStdout: true).trim()
try {
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}"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment