0

I'm trying to set up TeamCity to run tests on a .NET project. I have installed TeamCity and its agent (with access to docker) using docker compose :

  teamcity:
    image: jetbrains/teamcity-server
    container_name: teamcity
    volumes:
     - /home/arsene/teamcity/data:/data/teamcity_server/datadir
     - /home/arsene/teamcity/logs:/opt/teamcity/logs
    environment:
      - TEAMCITY_HTTPS_PROXY_ENABLED=true
    labels:
      - traefik.http.routers.teamcity.rule=Host(`myhost`)
      - traefik.http.routers.teamcity.tls=true
      - traefik.http.routers.teamcity.tls.certresolver=le   
      - traefik.http.services.teamcity.loadbalancer.server.port=8111

  teamcityagent:
    image: jetbrains/teamcity-agent
    container_name: teamcityagent
    volumes:
     - /home/arsene/teamcity/agent:/data/teamcity_agent/conf
     - /var/run/docker.sock:/var/run/docker.sock
     - /opt/buildagent/work:/opt/buildagent/work
     - /opt/buildagent/temp:/opt/buildagent/temp
    environment:
      - AGENT_NAME=TeamCityRunner
      - SERVER_URL=myhost
      - DOCKER_IN_DOCKER=start
    privileged: true

When I configure my project I select the following config :

TeamCity Config

TeamCity Config

But my build fail with very few detail about whats wrong.

Step 1/2: Test (.NET)
  Running step within Docker container mcr.microsoft.com/dotnet/sdk:5.0
  dotnet test
    Starting: .NET SDK 5.0.408 /usr/bin/dotnet test /opt/buildagent/work/e83eb8da5bf3868c/ImPresent.Tests/ImPresent.Tests.csproj @/opt/buildagent/temp/agentTmp/1.rsp
    in directory: /opt/buildagent/work/e83eb8da5bf3868c
    MSBUILD : error MSB1021: Cannot create an instance of the logger. The given assembly name or codebase was invalid. (0x80131047)
    Switch: TeamCity.MSBuild.Logger.TeamCityMSBuildLogger,/opt/buildagent/plugins/dotnet/tools/msbuild15/TeamCity.MSBuild.Logger.dll;TeamCity;plain
    Process exited with code 1
    Process exited with code 1 (Step: Test (.NET))
  Step Test (.NET) failed

Do you have any idea of what could be wrong, or how to check logs the have more details ? I ran my tests in the same container on my desktop, they pass.

2 Answers 2

0

Two things I would try:

  1. Add "Build" Step before testing:

    Runner Type: .NET.

    Command: build.

    Also it may be required to add another build configuration to Restore the project before build.

  2. Execute this build step in "verbose" mode to get more logging information.

0

Teamcity agent is totally unable to detect it is running in docker and try to mount its own directories instead of the proper volumes into the launched container for the step (observed from a problem I encountered with a command line step to run a script within a docker environment).

You need to use command line step and do something like this (untested with .Net but should give the idea, you may need to install jq into the agent container too):

MOUNTS=$( docker inspect teamcityagent | jq '.[0].Mounts[] | select(.Destination | contains("/opt/buildagent/")) | "-v \(.Name):\(.Destination)" ' -r | tr '\n' ' ')
docker pull mcr.microsoft.com/dotnet/sdk:5.0
docker run --rm $MOUNTS -w %teamcity.build.workingDir% mcr.microsoft.com/dotnet/sdk:5.0 /usr/bin/dotnet test %teamcity.build.workingDir%/ImPresent.Tests/ImPresent.Tests.csproj

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.