Multi-build job on TeamCity don't work with Sonar Scanner (Parameters + mono Repo)

which versions are you using: * Enterprise Edition* v10.6 (92116) | Scanner .4.2.0.1873
how is SonarQube deployed: Zip folder on Windows Server (IIS + Reverse Proxy and Win Service)

what are you trying to achieve : I have a TeamCity professional 2024.07.2 (build 160695) job, this is a multi-build job, so the developers can select multiple services to be built from different folder / projects in a monorepo on Azure Devops, this mono repo contains all the projects/services, and i am using teamcity.xml to use parameters environment+services to set where and what will be built.

I want each of this services to become a project in Sonarque and everytime i build happens this project is updated with a new analysis. The challenge is i can’t find a way to parametrize the SonarQube scanner step in order to meet the parameters i have in the job to achieve what i described (one project per service in sonar)

what have you tried so far to achieve this : i have tried to use the variable %system.Services% in the project name and project key field of sonar scanner step, this way if the user select a specific service in the job parameters, i will automatically change it and report to sonar following the selection, in the sources location i also used a variable to set the TeamCity server default folder + the %system.services% variable, this way it will look always and only to the folder where services selected is located in the repo.

It worked when only one service is selected, the challenge now is, when the dev selects multiple services, sonar scanner step just concatenates the services selected in the %system.services% variable, creating the project in sonar with the concatenated string, also failing to run the scanner, because it also concatenates the path of sources location.

I was wondering if there is a way to execute a custom script where i can set a logic (kind of a for each based on the services select where the scanner would run for each and report to Sonar) or any other solution for this challenge i described.

Team city multi build job is pretty helpful and make developers life easier, so would be nice to keep it and also have sonar properly configured.

Many thanks in advance

Hi,

SonarScanner isn’t designed to do what you’re trying to do with it. You’ll need your job to work differently: for each service, fire off the scanner with the relevant values passed on the command line.

 
HTH,
Ann