Jenkins 上的 Mstest 在 foreach 循环中首次调用后输出不需要的 UTF-8 字符
Mstest on Jenkins outputs undesired UTF-8 characters after first call in a foreach loop
我目前正在尝试使用 Jenkins 为我们的一个软件设置一个 CI 管道。我正处于需要使用 MsTest 运行 每个单独的测试文件的步骤。据我所知,与 NUnit 或其他流行的测试框架不同,MsTest 不允许您 运行 解决方案文件夹中的所有测试。我必须递归检查解决方案文件夹中的每个文件夹,并手动 运行 ForEach-Object 循环中的每个测试容器。目前,前几个测试套件 运行 完美并打印出日志。然而,在测试阶段进行到一半时,Jenkins 日志中出现了一些奇怪的字符,似乎导致测试失败。
我在网上看过,在大多数类似的情况下,运行 解决这个问题的人使用的是旧版本的插件,但我不是这种情况。我们正在使用 Jenkins 2.15 和 PowerShell 4.0。这是测试阶段的代码。
stage ('Unit tests') {
steps {
script {
powershell("""
Get-ChildItem -Path .\*\bin\*Tests.dll -Recurse |
ForEach-Object {
$obj = $_;
& \"${tool 'MsTest'}\" /category:.\"ExpectedState|CurrentState|Uncategorized\" /testcontainer:\"$obj\";
}
""")
}
}
}
这是 Jenkins 日志的部分输出
Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0
Copyright (c) Microsoft Corporation. All rights reserved.
Loading D:\jenkins-workspace\workspace\MultiBranch_Pipeline\Acceptance.Tests\bin\Release\Acceptance.Tests.dll...
Starting execution...
Summary
Test Run Inconclusive.
Inconclusive 7
Total 7
结果文件:D:\jenkins->workspace\workspace\MultiBranch_Pipeline\TestResults\JenkinsAdmin 2019-04-02 13_47_54.trx
测试设置:默认测试设置
然后最终在 ForEach 循环中
Starting execution...
No tests to execute.
powershell.exe : 
在 D:\jenkins-workspace\workspace\MultiBranch_Pipeline\durable-5fe1\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "& 'D:\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (ï »¿
- FullyQualifiedErrorId : NativeCommandError
这些奇怪的角色似乎很 运行domly 生成,我不确定是什么让它们出现。这是我的问题还是其中一个插件的问题?
对不起,如果之前有人问过这个问题,我在网上看到的情况下找不到解决方案。感谢您花时间阅读。
我自己的聚会迟到了,但我终于用这个答案解决了这个问题。
我忽略了这个答案,因为我认为我的问题出在其他地方,但这确实是我想要的。
编辑:
According to this answer:
JVM property -Dfile.encoding=UTF8 or UTF-8?
You have to add this JVM setting to your Jenkins starting script
(JAVA_TOOLS_OPTIONS):
-Dfile.encoding=UTF8
我目前正在尝试使用 Jenkins 为我们的一个软件设置一个 CI 管道。我正处于需要使用 MsTest 运行 每个单独的测试文件的步骤。据我所知,与 NUnit 或其他流行的测试框架不同,MsTest 不允许您 运行 解决方案文件夹中的所有测试。我必须递归检查解决方案文件夹中的每个文件夹,并手动 运行 ForEach-Object 循环中的每个测试容器。目前,前几个测试套件 运行 完美并打印出日志。然而,在测试阶段进行到一半时,Jenkins 日志中出现了一些奇怪的字符,似乎导致测试失败。
我在网上看过,在大多数类似的情况下,运行 解决这个问题的人使用的是旧版本的插件,但我不是这种情况。我们正在使用 Jenkins 2.15 和 PowerShell 4.0。这是测试阶段的代码。
stage ('Unit tests') {
steps {
script {
powershell("""
Get-ChildItem -Path .\*\bin\*Tests.dll -Recurse |
ForEach-Object {
$obj = $_;
& \"${tool 'MsTest'}\" /category:.\"ExpectedState|CurrentState|Uncategorized\" /testcontainer:\"$obj\";
}
""")
}
}
}
这是 Jenkins 日志的部分输出
Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0 Copyright (c) Microsoft Corporation. All rights reserved.
Loading D:\jenkins-workspace\workspace\MultiBranch_Pipeline\Acceptance.Tests\bin\Release\Acceptance.Tests.dll... Starting execution...
Summary
Test Run Inconclusive.
Inconclusive 7
Total 7
结果文件:D:\jenkins->workspace\workspace\MultiBranch_Pipeline\TestResults\JenkinsAdmin 2019-04-02 13_47_54.trx
测试设置:默认测试设置
然后最终在 ForEach 循环中
Starting execution... No tests to execute.
powershell.exe : 
在 D:\jenkins-workspace\workspace\MultiBranch_Pipeline\durable-5fe1\powershellWrapper.ps1:3 char:1 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "& 'D:\ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (ï »¿
- FullyQualifiedErrorId : NativeCommandError
这些奇怪的角色似乎很 运行domly 生成,我不确定是什么让它们出现。这是我的问题还是其中一个插件的问题?
对不起,如果之前有人问过这个问题,我在网上看到的情况下找不到解决方案。感谢您花时间阅读。
我自己的聚会迟到了,但我终于用这个答案解决了这个问题。
我忽略了这个答案,因为我认为我的问题出在其他地方,但这确实是我想要的。
编辑:
According to this answer: JVM property -Dfile.encoding=UTF8 or UTF-8?
You have to add this JVM setting to your Jenkins starting script (JAVA_TOOLS_OPTIONS):
-Dfile.encoding=UTF8