From 2f0d127ef88ed4dda22dce91e5ebaff28ca2113f Mon Sep 17 00:00:00 2001 From: "James Truher [MSFT]" Date: Mon, 1 Apr 2019 16:47:55 -0700 Subject: [PATCH] Check to be sure that the test result file has actual results before uploading (#9253) VSTS produces a warning if the result set is 0, we will skip uploading this to avoid the warning and better support automation scenarios. ## PR Context We have automation which checks our test results and if the result set is 0 for that file, a warning is produced. This PR will avoid uploading that file into the test results (which is valid, as there are no run tests). We will still add the file to our artifact list for completeness. --- build.psm1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index c61750c9ec..4932eab761 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1230,7 +1230,13 @@ function Publish-TestResults $_ -replace 'result="Ignored"', 'result="Skipped"' } | Out-File -FilePath $tempFilePath -Encoding ascii -Force - Write-Host "##vso[results.publish type=$Type;mergeResults=true;runTitle=$Title;publishRunAttachments=true;resultFiles=$tempFilePath;]" + # If we attempt to upload a result file which has no test cases in it, then vsts will produce a warning + # so check to be sure we actually have a result file that contains test cases to upload. + # If the the "test-case" count is greater than 0, then we have results. + # Regardless, we want to upload this as an artifact, so this logic doesn't pertain to that. + if ( @(([xml](Get-Content $Path)).SelectNodes(".//test-case")).Count -gt 0 -or $Type -eq 'XUnit' ) { + Write-Host "##vso[results.publish type=$Type;mergeResults=true;runTitle=$Title;publishRunAttachments=true;resultFiles=$tempFilePath;]" + } $resolvedPath = (Resolve-Path -Path $Path).ProviderPath Write-Host "##vso[artifact.upload containerfolder=testResults;artifactname=testResults]$resolvedPath"