diff --git a/eng/pipelines/templates/BuildAndTest.yml b/eng/pipelines/templates/BuildAndTest.yml index cfd2528f6f6..92717160bf4 100644 --- a/eng/pipelines/templates/BuildAndTest.yml +++ b/eng/pipelines/templates/BuildAndTest.yml @@ -58,6 +58,48 @@ steps: "${{ parameters.buildScript }} -test -configuration ${{ parameters.buildConfig }} /bl:${{ parameters.repoLogPath }}/tests.binlog $(_OfficialBuildIdArgs)" displayName: Run tests + - pwsh: | + $SourcesDirectory = '$(Build.SourcesDirectory)'; + + $destinationPath = "${{ parameters.repoLogPath }}/FailedAssertions" + if (-not (Test-Path -Path $destinationPath)) { + New-Item -Path $destinationPath -ItemType Directory -Force | Out-Null + } + + Get-ChildItem $SourcesDirectory -Filter "*.received.*" -Recurse | ` + ForEach-Object { + # Exclude files that are already in the test results path + if ($_.FullName -like "*FailedAssertions*") { + return + } + + if ($_.PSIsContainer) { + # Delete the folder if it exists + $dest = Join-Path -Path $destinationPath -ChildPath $_.Name + if (Test-Path -Path $dest) { + Remove-Item -Path $dest -Recurse -Force + } + # Copy folder to logs + Copy-Item -Path $_.FullName -Destination $destinationPath -Recurse -Force + } + else { + # Calculates the relative path of the file with respect to `$SourcesDirectory`. + $relativePath = [System.IO.Path]::GetRelativePath($SourcesDirectory, $_.FullName) + # Constructs the full destination path for the file, preserving the relative directory structure. + $destinationFile = Join-Path -Path $destinationPath -ChildPath $relativePath + $destinationDirectory = [System.IO.Path]::GetDirectoryName($destinationFile) + # Ensures the destination directory exists (creates it if necessary). + if (-not (Test-Path -Path $destinationDirectory)) { + New-Item -Path $destinationDirectory -ItemType Directory -Force | Out-Null + } + # Copies the file to the destination path. + Copy-Item -Path $_.FullName -Destination $destinationFile -Force + } + } + displayName: Copy failed assertions results to logs + condition: always() + continueOnError: true + - pwsh: | Get-ChildItem ${{ parameters.repoTestResultsPath }} -Include "*_hangdump.dmp","Sequence_*.xml" -Recurse | ` ForEach-Object {