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
6ae3e762
Commit
6ae3e762
authored
Mar 19, 2026
by
Auto Backup
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 统一命令执行函数,Windows强制使用PowerShell 7 (pwsh)执行
parent
f1d01398
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
13 deletions
+7
-13
Jenkinsfile
Jenkinsfile
+5
-4
environment-check.Jenkinsfile
environment-check.Jenkinsfile
+2
-9
No files found.
Jenkinsfile
View file @
6ae3e762
// 新增带返回值的跨平台 PowerShell 执行函数
def
runPowerShellWithOutput
(
script
)
{
try
{
if
(
isUnix
())
{
return
sh
(
script:
"pwsh -Command \"${script}\""
,
returnStdout:
true
).
trim
()
if
(
isUnix
())
{
// 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([
...
...
environment-check.Jenkinsfile
View file @
6ae3e762
...
...
@@ -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}"
...
...
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