VSTS "Visual Studio Test" 任务在发布后删除 TRX 文件

VSTS "Visual Studio Test" task deletes TRX file after publish

我继承了一个 jacked VSTS 构建过程,我正在尝试将 SonarQube 集成到组合中。 Jacked,因为它不是一个干净的安装,我知道以前的所有者用它做了一些奇怪而神秘的事情,我还没有找到。

无论如何,我遇到的问题是 "Visual Studio Test" 任务步骤在发布结果后删除了 .trx 文件。我需要 SonarQube 的 .trx 文件。我可以看到 trx 文件正在被删除,并且在文件夹的屏幕录制和 VSTS 构建过程的活动控制台日志记录之后精确定位了 .trx 文件消失的发布过程。 system.debug = true 这里是日志的一个子集(.trx 文件在这里某处消失):

Test results remaining: 165. Test run id: 33.
Leaving UpdateTestResultsAsync
Updated test results: 165
Publishing Attachments: 2
Entering CreateTestRunAttachmentsAsync
Leaving CreateTestRunAttachmentsAsync
Uploading test run attachements individually
Completed PublishTestResult
Completed Publish Test Results: 0

我尝试了很多方法,最近的尝试是将最新的 VS 2017 Enterprise IDE 安装到构建机器上,并在任务中使用这些设置:

不确定这是否有帮助,但这是上面进行的 vstest 调用的近似值,如控制台所示:

vstest.console.exe /TestCaseFilter:"FullyQualifiedName=<all the dlls in my solution>"
"C:\agent\_work\s\Source\Sln\Project1\bin\Debug\net461\Project1.Tests.dll"
"C:\agent\_work\s\Source\Sln\Project2\bin\Debug\net461\Project2.Tests.dll"
"C:\agent\_work\s\Source\Sln\Project3\bin\Debug\net461\Project3.Tests.dll"
/EnableCodeCoverage
/InIsolation
/logger:"trx"
/TestAdapterPath:"C:\agent\_work\s\Source\Sln"
/diag:"C:\agent\_work\_tempacf64a0-4b51-11e8-9bf5-3b4a52af383b.txt"

-#############################

如果我从命令行 运行 vstest.console.exe,则不会发布结果,也不会删除 .trx 文件。

-#############################

我希望 Visual Studio 测试任务步骤发布但不删除 .trx 文件。

如有任何帮助,我们将不胜感激。谢谢!

-###################

更新 1:最后 "Completed Test Execution" 部分的附加日志记录:

**************** Completed test execution *********************
Current Phase: MS.VS.TestService.VstestConsoleAdapter.ExecuteVsTestPhase Phase Result: MS.VS.TestService.VstestConsoleAdapter.ExecutionVsTestPhaseResults
PERF WARNING: Running the phase MS.VS.TestService.VstestConsoleAdapter.ExecuteVsTestPhase: took 5414.7701 ms
Current phase: MS.VS.TestService.VstestConsoleAdapter.PublishTestResultPhase
Starting Publish Test Results: TIA: False
Starting PublishTestResult
Test results files: C:\agent\_work\s\TestResults\SERVERNAME$_SERVERNAME_2018-04-30_07_43_27.trx
Updating Test results: 35
Entering ParseTestResultFiles
runContext.Platform is null
runContext.Configuration is null
runContext.ReleaseURI is null
runContext.ReleaseEnvironmentUri is null
Reading test results from file 'C:\agent\_work\s\TestResults\SERVERNAME$_SERVERNAME_2018-04-30_07_43_27.trx'.
Setting run start and finish times.
Attachment location: C:\agent\_work\s\TestResults\SERVERNAME$_SERVERNAME_2018-04-30_07_43_27\In.
Adding run level attachment: C:\agent\_work\s\TestResults\SERVERNAME$_SERVERNAME_2018-04-30_07_43_27\In\SERVERNAME\SYSTEM_SERVERNAME 2018-04-30 07_43_21.coverage.
Total test results: 168.
Leaving ParseTestResultFiles
pdating test results: 168
Entering UpdateTestResultsAsync
Publishing test results to test run '35'.
PERF: GetTestCaseResults: took 333.1965 ms
PERF WARNING: GetTestCaseResults: took 333.1965 ms
Test results remaining: 165. Test run id: 35.
Leaving UpdateTestResultsAsync
Updated test results: 165
Publishing Attachments: 2
Entering CreateTestRunAttachmentsAsync
Leaving CreateTestRunAttachmentsAsync
Uploading test run attachements individually
Completed PublishTestResult
Completed Publish Test Results: 0
Current Phase: MS.VS.TestService.VstestConsoleAdapter.PublishTestResultPhase Phase Result: MS.VS.TestService.VstestConsoleAdapter.PublishTestResultPhaseResults
PERF WARNING: Running the phase MS.VS.TestService.VstestConsoleAdapter.PublishTestResultPhase: took 1719.7748 ms
Current phase: MS.VS.TestService.VstestConsoleAdapter.RerunValidationPhase
Started RerunValidationPhase for 35
Maximum number of attempts running the failed tests reached: 3
Processed: ##vso[task.logissue type=warning;]Maximum number of attempts running the failed tests reached: 3
Current Phase: MS.VS.TestService.VstestConsoleAdapter.RerunValidationPhase Phase Result: MS.VS.TestService.VstestConsoleAdapter.RerunValidationPhaseResults
PERF: Running the phase MS.VS.TestService.VstestConsoleAdapter.RerunValidationPhase: took 1.1836 ms
Current phase: MS.VS.TestService.VstestConsoleAdapter.CleanupPhase
Started CleanupPhase 35
Test run needs to be marked as complete.
Entering UpdateTestRunAsync
Leaving UpdateTestRunAsync
Completed CleanupPhase 35
Current Phase: MS.VS.TestService.VstestConsoleAdapter.CleanupPhase Phase Result: MS.VS.TestService.VstestConsoleAdapter.CleanupPhaseResults
PERF: Running the phase MS.VS.TestService.VstestConsoleAdapter.CleanupPhase: took 259.2514 ms
Completed the ExecutionStateModel
Completed TestExecution Model...
rc:0
success:true
File exists. Size: 1224675 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.txt
Agent.Version=2.133.3
Agent.TempDirectory=C:\agent\_work\_temp
defaultRoot: 'C:\agent\_work\_temp'
findOptions.followSpecifiedSymbolicLink: 'true'
findOptions.followSymbolicLinks: 'true'
matchOptions.debug: 'false'
matchOptions.nobrace: 'true'
matchOptions.noglobstar: 'false'
matchOptions.dot: 'true'
matchOptions.noext: 'false'
matchOptions.nocase: 'true'
matchOptions.nonull: 'false'
matchOptions.matchBase: 'false'
matchOptions.nocomment: 'false'
matchOptions.nonegate: 'false'
matchOptions.flipNegate: 'false'
pattern: '*host.*.txt'
findPath: 'C:\agent\_work\_temp'
statOnly: 'false'
findPath: 'C:\agent\_work\_temp'
findOptions.followSpecifiedSymbolicLink: 'true'
findOptions.followSymbolicLinks: 'true'
C:\agent\_work\_temp (directory)
C:\agent\_work\_temp\.taskkey (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-43-19_00381_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-25_11343_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-35_20720_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-42_87908_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-43-22_36319_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-25_98843_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-36_03532_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-43_70721_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.txt (file)
C:\agent\_work\_temp\cc80b061-4c84-11e8-87c2-ab8f332e19bd.txt (file)
C:\agent\_work\_temp\cc80b063-4c84-11e8-87c2-ab8f332e19bd.txt (file)
C:\agent\_work\_temp\proxy (file)
14 results
found 14 paths
applying include pattern
adjustedPattern: 'C:\agent\_work\_temp\*host.*.txt'
4 matches
pattern: '*datacollector.*.txt'
findPath: 'C:\agent\_work\_temp'
statOnly: 'false'
findPath: 'C:\agent\_work\_temp'
findOptions.followSpecifiedSymbolicLink: 'true'
findOptions.followSymbolicLinks: 'true'
C:\agent\_work\_temp (directory)
C:\agent\_work\_temp\.taskkey (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-43-19_00381_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-25_11343_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-35_20720_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-42_87908_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-43-22_36319_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-25_98843_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-36_03532_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-43_70721_1.txt (file)
C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.txt (file)
C:\agent\_work\_temp\cc80b061-4c84-11e8-87c2-ab8f332e19bd.txt (file)
C:\agent\_work\_temp\cc80b063-4c84-11e8-87c2-ab8f332e19bd.txt (file)
C:\agent\_work\_temp\proxy (file)
14 results
found 14 paths
applying include pattern
adjustedPattern: 'C:\agent\_work\_temp\*datacollector.*.txt'
4 matches
8 final results
File exists. Size: 11672 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-43-19_00381_1.txt
File exists. Size: 11672 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-25_11343_1.txt
File exists. Size: 11671 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-35_20720_1.txt
File exists. Size: 11582 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.datacollector.18-04-30_07-45-42_87908_1.txt
File exists. Size: 413384 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-43-22_36319_1.txt
File exists. Size: 45500 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-25_98843_1.txt
File exists. Size: 45350 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-36_03532_1.txt
File exists. Size: 45500 Bytes
Processed: ##vso[task.uploadfile]C:\agent\_work\_temp\cc80b060-4c84-11e8-87c2-ab8f332e19bd.host.18-04-30_07-45-43_70721_1.txt
task result: Succeeded
Processed: ##vso[task.complete result=Succeeded;]VsTest task succeeded.
Agent.Version=2.133.3
Release.ReleaseUri=undefined
Release.ReleaseId=undefined
Build.BuildUri=vstfs:///Build/Build/745
Build.Buildid=745
Agent.Version=2.133.3
telemetry area: TestExecution feature: TestExecutionTask data: {"builduri":"vstfs:///Build/Build/745","buildid":"745","codeCoverageEnabled":true,"overrideTestrunParameters":"false","pipeline":"build","runTestsInIsolation":true,"task":"VsTestConsoleFlow","runInParallel":false,"result":"Succeeded","settingsType":"none","testSelection":"testAssemblies","tiaEnabled":false,"vsTestVersion":"15.0.27428","consoleOptionsEnabled":"","rerunEnabled":true,"rerunType":"basedOnTestFailurePercentage"}
Processed: ##vso[telemetry.publish area=TestExecution;feature=TestExecutionTask;]{"builduri":"vstfs:///Build/Build/745","buildid":"745","codeCoverageEnabled":true,"overrideTestrunParameters":"false","pipeline":"build","runTestsInIsolation":true,"task":"VsTestConsoleFlow","runInParallel":false,"result":"Succeeded","settingsType":"none","testSelection":"testAssemblies","tiaEnabled":false,"vsTestVersion":"15.0.27428","consoleOptionsEnabled":"","rerunEnabled":true,"rerunType":"basedOnTestFailurePercentage"}

我也可以重现结果。

对于版本为 2.* 的 VS 测试任务,执行 VS 测试任务后将删除 .trx 文件。

如果您需要在 VS 测试任务后获取 .trx 文件,您可以使用版本 1.* 的 VS 测试任务。它会将 .trx 文件保留在源目录中。

我知道这是一个旧的 post,但是寻找解决方案的人会受益于它与任务的最新版本一起使用。您需要添加路径以将结果保存在与“$(Agent.TempDirectory)/TestResults”不同的文件夹中,后者将在管道 运行 的末尾被删除。 从任务"Test results folder"的信息...

Folder to store test results. When this input is not specified, results are stored in $(Agent.TempDirectory)/TestResults by default, which is cleaned at the end of a pipeline run. The results directory will always be cleaned up at the start of the vstest task before the tests are run. Relative folder path if provided will be considered relative to $(Agent.TempDirectory)

我已经通过让任务变量 "Test results folder" 指向临时目录以外的文件夹解决了这个问题。有了这个,我可以在任务 运行 之后保留 trx 文件。就我而言,我需要 trx 文件进行进一步处理。

这里有一个可能的解决方案 https://developercommunity.visualstudio.com/content/problem/747717/vstest-not-creating-trx-in-folder-testresults.html

打开

Build Details -> Tests -> Filter in Passed Tests -> Open Test Run -> Attachments

文件已经在服务器上,但不是工件,而是在测试运行中