Skip to content

Commit 8088b0b

Browse files
authored
Merge pull request #11319 from navin22/users/navb/v1taskchangeport
Port M156 : Using the agent command to publish in VsTestV1 and PTRV1 tasks.
2 parents 8583bfc + b585c41 commit 8088b0b

File tree

13 files changed

+126
-46
lines changed

13 files changed

+126
-46
lines changed

Tasks/PublishTestResultsV1/PublishTestResults.ps1

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,46 +61,91 @@ try
6161
}
6262
else
6363
{
64+
$switchToPowerShell = Get-TaskVariable -Context $distributedTaskContext -Name "UsePowerShellScripts"
65+
$agentVersionVar = Get-TaskVariable -Context $distributedTaskContext -Name "Agent.Version"
66+
Write-Verbose "Agent Version: $agentVersionVar"
67+
68+
try {
69+
$agentVersion = [version]$agentVersionVar;
70+
}
71+
catch {
72+
Write-Verbose "Invalid Agent version : $agentVersionVar";
73+
}
74+
75+
# There's a Null reference exception introduced in the agent 2.138 until 2.138.4 and hot fixed in 2.138.5.
76+
# Hence falling back to Scripts to pulblish test results. If Agent version falls between 2.138 .. 2.138.4
77+
if (!$agentVersion -or (($agentVersion -ge [version]"2.138") -and ($agentVersion -le [version]"2.138.4"))) {
78+
$switchToPowerShell = "true";
79+
}
80+
81+
if ($switchToPowerShell -ieq "true") {
82+
Write-Verbose "Using the powershell scripts to publish test results"
83+
}
84+
else {
85+
Write-Verbose "Using Agent Command to publish test results"
86+
}
87+
88+
$testRunSystem = "VSTS - PTR";
6489
$publishResultsOption = Convert-String $publishRunAttachments Boolean
6590
$mergeResults = Convert-String $mergeTestResults Boolean
6691
Write-Verbose "Calling Publish-TestResults"
6792

6893
$publishRunLevelAttachmentsExists = CmdletHasMember "PublishRunLevelAttachments"
6994
$runTitleMemberExists = CmdletHasMember "RunTitle"
70-
if(!($runTitleMemberExists))
71-
{
72-
if(!([string]::IsNullOrWhiteSpace($testRunTitle)))
73-
{
74-
Write-Warning "Update the build agent to be able to use the custom run title feature."
75-
}
76-
if($publishRunLevelAttachmentsExists)
77-
{
78-
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext -PublishRunLevelAttachments $publishResultsOption
79-
}
80-
else
81-
{
82-
if(!$publishResultsOption)
83-
{
84-
Write-Warning "Update the build agent to be able to opt out of test run attachment upload."
85-
}
86-
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext
87-
}
88-
}
89-
else
90-
{
91-
if($publishRunLevelAttachmentsExists)
92-
{
93-
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext -PublishRunLevelAttachments $publishResultsOption -RunTitle $testRunTitle
94-
}
95-
else
96-
{
97-
if(!$publishResultsOption)
98-
{
99-
Write-Warning "Update the build agent to be able to opt out of test run attachment upload."
100-
}
101-
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext -RunTitle $testRunTitle
102-
}
103-
}
95+
if(!($runTitleMemberExists))
96+
{
97+
if(!([string]::IsNullOrWhiteSpace($testRunTitle)))
98+
{
99+
Write-Warning "Update the build agent to be able to use the custom run title feature."
100+
}
101+
if($publishRunLevelAttachmentsExists)
102+
{
103+
if ($switchToPowerShell -ieq "true") {
104+
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext -PublishRunLevelAttachments $publishResultsOption
105+
}
106+
else {
107+
Write-Host "##vso[results.publish type=$testRunner;mergeResults=$mergeResults;publishRunAttachments=$publishResultsOption;resultFiles=$matchingTestResultsFiles;platform=$platform;configuration=$configuration;testRunSystem=$testRunSystem;]"
108+
}
109+
}
110+
else
111+
{
112+
if(!$publishResultsOption)
113+
{
114+
Write-Warning "Update the build agent to be able to opt out of test run attachment upload."
115+
}
116+
if ($switchToPowerShell -ieq "true") {
117+
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext
118+
}
119+
else {
120+
Write-Host "##vso[results.publish type=$testRunner;mergeResults=$mergeResults;resultFiles=$matchingTestResultsFiles;platform=$platform;configuration=$configuration;testRunSystem=$testRunSystem;]"
121+
}
122+
}
123+
}
124+
else
125+
{
126+
if($publishRunLevelAttachmentsExists)
127+
{
128+
if ($switchToPowerShell -ieq "true") {
129+
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext -PublishRunLevelAttachments $publishResultsOption -RunTitle $testRunTitle
130+
}
131+
else {
132+
Write-Host "##vso[results.publish type=$testRunner;mergeResults=$mergeResults;publishRunAttachments=$publishResultsOption;resultFiles=$matchingTestResultsFiles;platform=$platform;configuration=$configuration;testRunSystem=$testRunSystem;runTitle=$testRunTitle;]"
133+
}
134+
}
135+
else
136+
{
137+
if(!$publishResultsOption)
138+
{
139+
Write-Warning "Update the build agent to be able to opt out of test run attachment upload."
140+
}
141+
if ($switchToPowerShell -ieq "true") {
142+
Publish-TestResults -TestRunner $testRunner -TestResultsFiles $matchingTestResultsFiles -MergeResults $mergeResults -Platform $platform -Configuration $configuration -Context $distributedTaskContext -RunTitle $testRunTitle
143+
}
144+
else {
145+
Write-Host "##vso[results.publish type=$testRunner;mergeResults=$mergeResults;resultFiles=$matchingTestResultsFiles;platform=$platform;configuration=$configuration;testRunSystem=$testRunSystem;runTitle=$testRunTitle;]"
146+
}
147+
}
148+
}
104149
}
105150
}
106151
catch

Tasks/PublishTestResultsV1/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"loc.friendlyName": "Publish test results",
3-
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?LinkID=613742)",
3+
"loc.helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613742)",
44
"loc.description": "Publish test results to Azure Pipelines",
55
"loc.instanceNameFormat": "Publish Test Results $(testResultsFiles)",
66
"loc.group.displayName.advanced": "Advanced",

Tasks/PublishTestResultsV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 0,
17-
"Patch": 42
17+
"Patch": 43
1818
},
1919
"demands": [],
2020
"minimumAgentVersion": "1.83.0",

Tasks/PublishTestResultsV1/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 0,
17-
"Patch": 42
17+
"Patch": 43
1818
},
1919
"demands": [],
2020
"minimumAgentVersion": "1.83.0",

Tasks/VsTestV1/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"loc.friendlyName": "Visual Studio Test",
3-
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?LinkId=624539)",
3+
"loc.helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?LinkId=624539)",
44
"loc.description": "Run tests with Visual Studio test runner",
55
"loc.instanceNameFormat": "Test Assemblies $(testAssembly)",
66
"loc.group.displayName.executionOptions": "Execution Options",

Tasks/VsTestV1/VSTest.ps1

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,41 @@ finally
244244

245245
if($resultFiles)
246246
{
247+
$switchToPowerShell = Get-TaskVariable -Context $distributedTaskContext -Name "UsePowerShellScripts"
248+
if ($switchToPowerShell -ieq "true") {
249+
Write-Verbose "Using the powershell scripts to publish test results"
250+
}
251+
else {
252+
Write-Verbose "Using Agent Command to publish test results"
253+
}
254+
247255
# Remove the below hack once the min agent version is updated to S91 or above
248256
$runTitleMemberExists = CmdletHasMember "RunTitle"
249257
$publishRunLevelAttachmentsExists = CmdletHasMember "PublishRunLevelAttachments"
258+
250259
if($runTitleMemberExists)
251260
{
252261
if($publishRunLevelAttachmentsExists)
253262
{
254-
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration -RunTitle $testRunTitle -PublishRunLevelAttachments $publishResultsOption
263+
if ($switchToPowerShell -ieq "true") {
264+
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration -RunTitle $testRunTitle -PublishRunLevelAttachments $publishResultsOption
265+
}
266+
else {
267+
Write-Host "##vso[results.publish type=VSTest;publishRunAttachments=$publishResultsOption;resultFiles=$resultFiles;platform=$platform;configuration=$configuration;testRunSystem=VSTest;runTitle=$testRunTitle;]"
268+
}
255269
}
256270
else
257271
{
258272
if(!$publishResultsOption)
259273
{
260274
Write-Warning (Get-LocalizedString -Key "Update the agent to try out the '{0}' feature." -ArgumentList "opt in/out of publishing test run attachments")
261275
}
262-
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration -RunTitle $testRunTitle
276+
if ($switchToPowerShell -ieq "true") {
277+
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration -RunTitle $testRunTitle
278+
}
279+
else {
280+
Write-Host "##vso[results.publish type=VSTest;resultFiles=$resultFiles;platform=$platform;configuration=$configuration;testRunSystem=VSTest;runTitle=$testRunTitle;]"
281+
}
263282
}
264283
}
265284
else
@@ -271,16 +290,26 @@ finally
271290

272291
if($publishRunLevelAttachmentsExists)
273292
{
274-
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration -PublishRunLevelAttachments $publishResultsOption
293+
if ($switchToPowerShell -ieq "true") {
294+
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration -PublishRunLevelAttachments $publishResultsOption
295+
}
296+
else {
297+
Write-Host "##vso[results.publish type=VSTest;publishRunAttachments=$publishResultsOption;resultFiles=$resultFiles;platform=$platform;configuration=$configuration;testRunSystem=VSTest;]"
298+
}
275299
}
276300
else
277301
{
278302
if(!$publishResultsOption)
279303
{
280304
Write-Warning (Get-LocalizedString -Key "Update the agent to try out the '{0}' feature." -ArgumentList "opt in/out of publishing test run attachments")
281305
}
282-
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration
283-
}
306+
if ($switchToPowerShell -ieq "true") {
307+
Publish-TestResults -Context $distributedTaskContext -TestResultsFiles $resultFiles -TestRunner "VSTest" -Platform $platform -Configuration $configuration
308+
}
309+
else {
310+
Write-Host "##vso[results.publish type=VSTest;resultFiles=$resultFiles;platform=$platform;configuration=$configuration;testRunSystem=VSTest;]"
311+
}
312+
}
284313
}
285314
}
286315
else

Tasks/VsTestV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 1,
2020
"Minor": 0,
21-
"Patch": 92
21+
"Patch": 93
2222
},
2323
"demands": [
2424
"vstest"

Tasks/VsTestV1/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"version": {
1919
"Major": 1,
2020
"Minor": 0,
21-
"Patch": 92
21+
"Patch": 93
2222
},
2323
"demands": [
2424
"vstest"

Tests-Legacy/L0/VsTestV1/Compat.OptOutOfPublishNotInCmdlet.ProvidedByTask.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ $distributedTaskContext = 'Some distributed task context'
2020
Register-Mock Get-TaskVariable { $sourcesDirectory } -- -Context $distributedTaskContext -Name "Build.SourcesDirectory"
2121
Register-Mock Get-TaskVariable { $workingDirectory } -- -Context $distributedTaskContext -Name "System.DefaultWorkingDirectory"
2222
Register-Mock Get-TaskVariable { "c:\temp\testresults" } -- -Context $distributedTaskContext -Name "Common.TestResultsDirectory"
23+
Register-Mock Get-TaskVariable { "true" } -- -Context $distributedTaskContext -Name "UsePowerShellScripts"
2324

2425
Register-Mock Find-Files { @("a.dll") } -- -SearchPattern $testAssembly -RootFolder $sourcesDirectory
2526
$resultFiles='c:\temp\TestResults\results.trx'

Tests-Legacy/L0/VsTestV1/Compat.TestRunTitleNotInCmdlet.ProvidedByTask.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ $distributedTaskContext = 'Some distributed task context'
2020
Register-Mock Get-TaskVariable { $sourcesDirectory } -- -Context $distributedTaskContext -Name "Build.SourcesDirectory"
2121
Register-Mock Get-TaskVariable { $workingDirectory } -- -Context $distributedTaskContext -Name "System.DefaultWorkingDirectory"
2222
Register-Mock Get-TaskVariable { "c:\temp\testresults" } -- -Context $distributedTaskContext -Name "Common.TestResultsDirectory"
23+
Register-Mock Get-TaskVariable { "true" } -- -Context $distributedTaskContext -Name "UsePowerShellScripts"
2324

2425
Register-Mock Find-Files { @("a.dll") } -- -SearchPattern $testAssembly -RootFolder $sourcesDirectory
2526
$resultFiles='c:\temp\TestResults\results.trx'

0 commit comments

Comments
 (0)