1

I would like to use the artifacts from my build stage for the test stage. But somehow the dotnet test command does not find any tests and instantly exits.

The dotnet restore & dotnet build command seem to work differently depending on whether executed locally or in the CI.

My .gitlab-ci:

image: mcr.microsoft.com/dotnet/sdk:7.0

variables:
  CONFIGURATION: 'Release'
  MSBUILDDISABLENODEREUSE: "1"
  TEST_RESULT_DIRECTORY: '.test-results'

default:
  tags:
    - .NET 6.0
    - WPF

stages:
  - Build
  - Test

Build:
  stage: Build
  script:
    - dotnet restore --no-cache
    - dotnet build --no-restore --configuration $CONFIGURATION
  artifacts:
    paths:
      - ./**/bin/Release
      - ./**/obj/Release
    expire_in: 1 day

Test:
  stage: Test
  needs:
    - job: Build
      artifacts: true
  script:
    - dotnet test --no-build --nologo --configuration $CONFIGURATION --test-adapter-path:. --logger:"junit;LogFilePath=../$TEST_RESULT_DIRECTORY/{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
  artifacts:
    when: always
    reports:
      junit: 
        - ./$TEST_RESULT_DIRECTORY/*.xml

Maybe I'm just missing a critical file in the artifacts, but by comparing the local and CI generated files I noticed just a difference in additional NuGet related files on local generation.

2 Answers 2

1

After some digging I found out that not all files which are needed for dotnet test are put in the obj/Release folder. Some of them are one level above.

The solution is to include the full obj directory.

  artifacts:
    paths:
      - ./**/bin/Release
      - ./**/obj
Sign up to request clarification or add additional context in comments.

Comments

0

For me, in the build job I was doing a

dotnet restore --no-cache --force --packages ".nuget"

I had to add the .nuget folder to the artifacts

  artifacts:
    paths:
      # Save the build outputs as artifacts
      - ./**/bin
      - ./**/obj
      - ./.nuget
    expire_in: 1 day

Otherwise I had problems such as

Data collection : Unable to find a datacollector with friendly name 'XPlat Code Coverage'.
Data collection : Could not find data collector 'XPlat Code Coverage'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.