You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自建.NET Pipeline运行缓慢(测试通过后挂起)及测试结果无法显示仪表盘问题求助

Hey there! Let's tackle your two pipeline issues step by step—first the mysterious 12-minute hang after tests pass, then getting your test results to show up in the dashboard.

Issue 1: Pipeline hangs for 12 minutes after tests pass

From your description, the core business logic only takes ~4 minutes, but the pipeline stalls for 12 minutes post-tests. Let's break down potential culprits in your YAML and environment:

Possible Causes & Fixes

  • Lingering processes on self-hosted agent
    Since you're using a self-hosted pool, leftover processes (like dotnet or test runners) often stick around after the test task finishes, forcing the pipeline to wait for them to exit. Log into your agent machine, check for running processes tied to your test project, and terminate them manually to see if the hang time drops. You can also add a post-test cleanup step to kill these processes explicitly.

  • Inefficient test task configuration
    Your original DotNetCoreCLI@2 test task has continueOnError: true, but if the test runner doesn't exit cleanly, it can block the pipeline. Try modifying the task to skip rebuilding (since you already ran a full build earlier) with the --no-build flag:

    - task: DotNetCoreCLI@2
      displayName: Run tests
      continueOnError: true
      inputs:
        command: test
        projects: '$(TestProjects)'
        publishRunAttachments: false
        arguments: '--configuration $(buildConfiguration) --verbosity normal --no-build'
    
  • Overly broad build scope
    Your dotnet build task targets **/*.csproj, which includes test projects. Building test projects is unnecessary (the test task can handle it, or you can skip building them entirely with --no-build). Narrow down the build to exclude test projects:

    - task: DotNetCoreCLI@2
      displayName: 'dotnet build'
      inputs:
        command: 'build'
        projects: |
          **/*.csproj
          !**/*Test*.csproj # Exclude test projects
        configuration: $(buildConfiguration)
        arguments: '--configuration $(buildConfiguration)'
    
  • Agent post-job cleanup delays
    Self-hosted agents often run cleanup tasks after a pipeline finishes (like deleting the working directory). If your workspace is large, this can take minutes. Check your agent settings to disable automatic cleanup (or adjust retention policies) to speed things up.

Issue 2: Test results don't show up after using script: dotnet test

When you run dotnet test via a script task, Azure DevOps doesn't automatically pick up the test results—you need to explicitly publish them using the PublishTestResults@2 task. Here's how to fix it:

Add this task right after your script test step:

- script: dotnet test --logger trx --framework netcoreapp3.1 --configuration $(buildConfiguration)
  displayName: Run tests via script
- task: PublishTestResults@2
  displayName: Publish test results to dashboard
  inputs:
    testResultsFormat: 'VSTest' # Matches the trx logger format
    testResultsFiles: '**/*.trx' # Find all trx files in the workspace
    failTaskOnFailedTests: false # Optional: Set to true if you want the pipeline to fail on test failures

This will upload the TRX test results file to Azure DevOps, and they'll appear in the pipeline dashboard under the "Tests" tab.

内容的提问来源于stack exchange,提问作者Trombone Man

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 09:54:04