Git Blame from analyses in Dockerized tests

Must-share information (formatted with Markdown):

  • which versions are you using SonarQube: , Scanner:
  • how is SonarQube deployed: Docker

We are using a monorepo to build and deploy multiple microservices as Docker containers. Our build system (TeamCity) checks out the code and does a docker build for our test target, which will copy a number of directories appropriate to the target service into the container image according to the Dockerfile, as well as installing sonar-scanner etc. The tests, with coverage, will then be run in the container so that they are as production-like as possible, utilising all of the container build and dependancy management.

The question is, as we are slightly removed from the git repo once analyzing inside the container, how to we connect to our git blame information? Credentials to access our git repo can be passed into the container if necessary if there is a way to connect to git.

Our typical test commands for python:

pytest -cov-config ${COVERAGERC:-.coveragerc} ....
coverage xml -o .python.coverage.xml
sonar-scanner -Dsonar.projectKey=$SONAR_PROJECT \
              -Dsonar.projectName=$SONAR_PROJECT \
              -Dsonar.sources=$SOURCE_PATH \
              -Dsonar.exclusions="**/test/**,**/test_*.py,$SONAR_EXCLUSIONS" \
              -Dsonar.token=$SONAR_TOKEN \
              -Dsonar.python.version=$PYTHON_VERSION \

Thank you


Welcome to the community!

To be clear, you check out, then move the code somewhere and analyze from that location?

That’s… not idea. You could try making sure you move the SCM files too (not sure that would work). Or you can first move to your analysis location and then check out. This is the preferred solution.

Alternately, since this seems at root to be about running the tests(?), you could

  • make sure test reports are generated with relative paths
  • copy those reports back to your original directory

And analyze from the original directory.