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
680ef948
Commit
680ef948
authored
Mar 27, 2026
by
Auto Backup
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: utf8
parent
e5ace154
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
Jenkinsfile
Jenkinsfile
+19
-6
No files found.
Jenkinsfile
View file @
680ef948
...
@@ -2,23 +2,36 @@
...
@@ -2,23 +2,36 @@
def
runPowerShellWithOutput
(
script
)
{
def
runPowerShellWithOutput
(
script
)
{
try
{
try
{
if
(
isUnix
())
{
if
(
isUnix
())
{
// Unix 系统使用 sh 执行命令
return
sh
(
script:
"${script}"
,
returnStdout:
true
).
trim
()
return
sh
(
script:
"${script}"
,
returnStdout:
true
).
trim
()
}
else
{
}
else
{
// Windows 系统优先使用 PowerShell 7 (pwsh),失败时回退到 PowerShell 5
// 核心逻辑:先切换 CMD 代码页到 65001 (UTF-8),再强制 PowerShell 输出编码
// 使用 @echo off 隐藏 chcp 的输出,只返回 script 的结果
def
utf8Wrapper
=
"""
@echo off
chcp 65001 > nul
powershell -NoProfile -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${script}"
"""
.
trim
()
// 同样的逻辑,优先尝试 pwsh (PowerShell 7)
try
{
try
{
return
bat
(
script:
"pwsh -NoProfile -Command \"${script}\""
,
returnStdout:
true
).
trim
()
def
pwshWrapper
=
"""
@echo off
chcp 65001 > nul
pwsh -NoProfile -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${script}"
"""
.
trim
()
return
bat
(
script:
pwshWrapper
,
returnStdout:
true
).
trim
()
}
catch
(
Exception
pwshError
)
{
}
catch
(
Exception
pwshError
)
{
echo
"⚠️
PowerShell 7 (pwsh) 执行失败,尝试使用 PowerS
hell 5: ${pwshError.message}"
echo
"⚠️
pwsh 执行失败,回退到 powers
hell 5: ${pwshError.message}"
return
bat
(
script:
"powershell -NoProfile -Command \"${script}\""
,
returnStdout:
true
).
trim
()
return
bat
(
script:
utf8Wrapper
,
returnStdout:
true
).
trim
()
}
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
echo
"执行
PowerShell
脚本失败: ${e.message}"
echo
"执行脚本失败: ${e.message}"
throw
e
throw
e
}
}
}
}
/**
/**
* 执行 Git log 命令,自动处理跨平台 % 转义问题
* 执行 Git log 命令,自动处理跨平台 % 转义问题
* @param format Git 的 --pretty 格式字符串(如 %an, %B, %ae)
* @param format Git 的 --pretty 格式字符串(如 %an, %B, %ae)
...
...
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