skip to Main Content

I build and test NET 6 app in docker which works well – I see test output in console. When I try to publish test results I encounter an error. Full task output:

Starting: Publish test results
============================================================================== Task : Publish Test Results Description : Publish test
results to Azure Pipelines Version : 2.170.1 Author :
Microsoft Corporation Help :
https://learn.microsoft.com/azure/devops/pipelines/tasks/test/publish-test-results
============================================================================== /usr/bin/dotnet –version
3.1.418 Async Command Start: Publish test results Publishing test results to test run ‘22493988’ Test results remaining: 65. Test run
id: 22493988

> ##[warning]Failed to publish test results: Cannot insert duplicate key row in object ‘TestResult.tbl_TestCaseReference’ with unique index

‘ix_TestCaseReference2’. The duplicate key value is (1, 3559, 0, 0, 0,
0x2b12334e709060df7748bee70b2472ff22c0b671ae3e3b997395858711e5eef5,
0x89d7d75814a51ce876ec351fcb9aec22313feeece07fb1d5a3023a3e7a1f634d,
UnitTest, 0, 0, ). Async Command End: Publish test results Finishing:
Publish test results

Copy test results and publish steps

- pwsh: |
    $id=docker images --filter "label=test=$(Build.BuildId)" -q | Select-Object -First 1
    docker create --name testcontainer $id
    docker cp testcontainer:/testresults ./testresults
    docker rm testcontainer
  displayName: 'Copy test results'

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'VSTest'
    testResultsFiles: '**/*.trx'
    searchFolder: '$(System.DefaultWorkingDirectory)/testresults'
  displayName: 'Publish test results' 

Copy tests results without errors:

Starting: Copy test results
============================================================================== Task : PowerShell Description : Run a PowerShell script on
Linux, macOS, or Windows Version : 2.170.1 Author :
Microsoft Corporation Help :
https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
============================================================================== Generating script.
========================== Starting Command Output =========================== /usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . ‘/vsts/agent/_work/_temp/20d795dd-e081-4216-b9b1-327d257bbcb2.ps1’
69ba144bfd471794f0e11047a2b214bd7190b96b5b47616957927125c740f266
testcontainer

Finishing: Copy test results

I took code from tutorial: https://www.programmingwithwolfgang.com/run-xUnit-inside-docker-during-ci-build

2

Answers


  1. Chosen as BEST ANSWER

    I contacted my colleagues and turns out it's a bug in Azure. I replaced VSTest publisher and format with XUnit publisher and XML format - the XML was successfully uploaded. Another issue was that XML was only for one project in solution, so I ended up dropping that step all together because I don't really need this information anyway (if test failed, so fails build).


    • The xunit test publisher may be an issue here.
    • Try resolving the error by t by changing Xunit to VSTest.
    • And also, you don’t necessarily need a separate Publish Test Results job in the pipeline because built-in tasks like the Visual Studio Test task automatically publish test results to the pipeline.

    Please refer this MSFT doc Publish Test Results task for more information.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search