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
f1d01398
Commit
f1d01398
authored
Mar 19, 2026
by
Auto Backup
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复命令执行函数,增强跨平台兼容性,解决powershell语法问题
parent
d3f046f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
environment-check.Jenkinsfile
environment-check.Jenkinsfile
+16
-8
No files found.
environment-check.Jenkinsfile
View file @
f1d01398
// 新增带返回值的跨平台
PowerShell
执行函数
def run
PowerShell
WithOutput(script) {
// 新增带返回值的跨平台
命令
执行函数
def run
Command
WithOutput(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 系统,尝试多种方式
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()
}
}
} catch (Exception e) {
echo "执行
PowerShell 脚本
失败: ${e.message}"
echo "执行
命令
失败: ${e.message}"
throw e
}
}
pipeline {
...
...
@@ -34,7 +42,7 @@ pipeline {
echo "🚀 开始运行环境检测..."
// 使用新创建的环境检测脚本
def envCheckResult = run
PowerShell
WithOutput("node ./check-environment.js")
def envCheckResult = run
Command
WithOutput("node ./check-environment.js")
echo "环境检测结果:"
echo envCheckResult
...
...
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