|
61 | 61 | } |
62 | 62 | else |
63 | 63 | { |
| 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"; |
64 | 89 | $publishResultsOption = Convert-String $publishRunAttachments Boolean |
65 | 90 | $mergeResults = Convert-String $mergeTestResults Boolean |
66 | 91 | Write-Verbose "Calling Publish-TestResults" |
67 | 92 |
|
68 | 93 | $publishRunLevelAttachmentsExists = CmdletHasMember "PublishRunLevelAttachments" |
69 | 94 | $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 | + } |
104 | 149 | } |
105 | 150 | } |
106 | 151 | catch |
|
0 commit comments