首页 > 解决方案 > .NET Core 项目的 GitLab CI 测试阶段失败

问题描述

我的 GitLab CI 遇到了麻烦。我的测试阶段的预期工作流程是:

当前的工作流程是:

我的解决方案如下所示:
-- yml 文件
-- MyApp
-- MyApp.Tests

我的 gitlab-runner 的版本是 12.4.1,我在 Windows 环境中使用 shell 执行器。

请在我的 yml 文件下面找到:

image: mcr.microsoft.com/dotnet/core/sdk:3.1
variables:
  EXE_RELEASE_FOLDER: 'Oncolin.UI.Desktop\bin\Release'
  # the folder inside the deploy folder 
  DEPLOY_FOLDER_APP: 'Oncolin.UI.Desktop\Builds'
  CONFIGURATION: 'release'

 #NUGET_PATH: 'C:\NuGet\nuget.exe'
 #MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe'
 #MSTEST_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\MSTest.exe'
 NUNIT_PATH: '.\packages\NUnit.ConsoleRunner.3.9.0\tools\nunit3-console.exe'

 SOLUTION: 'Oncolin.sln'

stages:
 - build
 - test

build:
  stage: build
  tags:
   - windows
script:
  - '& nuget restore' # restore Nuget dependencies
  - '& dotnet restore'
  - '& SonarScanner.MSBuild.exe begin /k:Oncolin /d:sonar.host.url=https://docker:10500 '
  - '& dotnet build -c release'
  - '& "$env:MSBUILD_PATH" "$env:SOLUTION" /t:Build /p:Configuration=Release' # build the project
  - '& SonarScanner.MSBuild.exe end'
artifacts:
  expire_in: 1 week # save gitlab server space, we copy the files we need to deploy folder later on
  paths:
    - '$env:EXE_RELEASE_FOLDER\*' # saving exe to copy to deploy folder
    - 'RNC.RULES.QUALITY.TESTS\*' # saving entire Test project so NUnit can run tests 
    - 'RNC.MODEL.TNM.TESTS\*' # saving entire Test project so NUnit can run tests 
    - 'Oncolin.Model.Tests\*' # saving entire Test project so NUnit can run tests 
  
test:
  stage: test
  tags:
    - windows
  allow_failure: false
  script:
    - '& dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=$CI_PROJECT_DIR\artifacts\{assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"' 
  artifacts:
    expire_in: 1 week # save gitlab server space, we copy the files we need to deploy folder later on
    when: always
    paths:
      - $CI_PROJECT_DIR\artifacts\*test-result.xml
    reports:
      junit:
        - $CI_PROJECT_DIR\artifacts\*test-result.xml
  dependencies:
    - build

有人可以向我解释为什么跳过下载和 dotnet 测试步骤吗?我希望我提供了足够的信息。

提前致谢。

标签: .net-corecontinuous-integrationgitlabnunit

解决方案


问题来自声纳扫描仪。即使我使用了 .Net Core 声纳扫描仪,我在测试阶段也遇到了同样的问题。
我不知道为什么,我已经浪费了太多时间来调查这个问题。

我通过创建一个专门用于运行声纳的新阶段来解决它,并在测试阶段之后运行它。


推荐阅读