We are trying to use Team City Container wrapper and we would like to have sonar start, build, test and sonar end with separate steps but when invoking this in containers sonar is not working (We must invoke all steps in one). We attach source code but sonar scanner start is doing something that is not visible in next steps. Can someone help with this?
Hi,
Welcome to the community!
It seems like you’ve figured out the solution.
Can you share why you want to do this in separate steps?
Ann
I want to stay with current experience where developers can browse logs separately for build, tests and sonar end. It is just easier to have this separated instead of one large log.
The start step puts sonarscanner pieces in place to hook into subsequent steps, but with a naive approach all that setup gets destroyed with the container at the end of the step (not the end of the build). When you finally get to the (separate) end step, none of the hooks were in place to track/capture things, so it seems start was never called, and then you get an error.
Here are notes on the (persistent) volumes we use for our .NET projects (I’ll paste the relevant pieces from the “Additional run arguments” part of the “Container Settings” in the various steps:
- install/update sonarscanner - We install dotnet-sonarscanner to an arbitrary (–tool-path) location on the agent for reuse across configurations.
-v dotnet-tools:%DotnetToolsPath%
- start/end sonarscanner - You can reuse the TeamCity agent’s Java installation, but that’s outside the scope of your problem.
-v dotnet-tools:%DotnetToolsPath%
-v sonarscanner-temp:%ContainerPath.MSBuildCurrent%\Microsoft.Common.targets\ImportBefore
Our current value for ContainerPath.MSBuildCurrent is: C:\Users\ContainerAdministrator\AppData\Local\Microsoft\MSBuild\Current
- build & test - Same as number 2, but you don’t need the Java stuff if you’ve figured it out.
Obviously things will be a bit different for other languages, so you may need to investigate the particulars of how SonarScanner hooks into your language, but hopefully this is a helpful reference.
Thanks for sharing - I will try with those tips