Overwrite the dotnet project name in SonarQube doesn't work

Hi Community,

I’am using the “SonarScanner for .NET” to analyze our dotnet source code. I want that the results are visible on the sonarqube server with the name “terminal-app”. But I always see in our pipeline that the old name “sam-terminal-app” is used instead of “terminal-app”.

How in the documentation described I use the argument “/n: …” to specify the name of the analyzed project.

CI/CD code

sonar_scan:
  extends: .windows-runners
  stage: quality
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - dotnet C:\tools\Sonar\SonarScanner.MSBuild.dll begin /k:"sam-terminal.SONAR.terminal-app" /n:"terminal-app" /d:sonar.token=$SONAR_TOKEN
    - dotnet build ./src/TerminalV3.sln
    - dotnet C:\tools\Sonar\SonarScanner.MSBuild.dll end /d:sonar.login=$SONAR_TOKEN
  rules:
   - if: '$CI_COMMIT_REF_NAME == "main" || $CI_PIPELINE_SOURCE == "merge_request_event"'
     allow_failure: true

I have also removed the folders “C:\tools\GitlabRunner\builds” and “C:\tools\GitlabRunner\cache” to ensure that noting is read from cache.

GitlabRunner logs

SonarScanner for MSBuild 5.13
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
INFO: Scanner configuration file: C:\tools\Sonar\sonar-scanner-4.8.0.2856\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\tools\GitlabRunner\builds\ybdPSipn\0\sam-terminal\terminal-app\.sonarqube\out\sonar-project.properties
INFO: SonarScanner 4.8.0.2856
INFO: Java 17.0.7 Oracle Corporation (64-bit)
INFO: Windows Server 2022 10.0 amd64
INFO: User cache: C:\tools\GitlabRunner\builds\ybdPSipn\0\sam-terminal\terminal-app\.sonar\cache
INFO: Analyzing on SonarQube server 9.9.1.69595
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=367ms
INFO: Server id: xxxxxxxxx
INFO: User cache: C:\tools\GitlabRunner\builds\ybdPSipn\0\sam-terminal\terminal-app\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=94ms
INFO: Load/download plugins (done) | time=10999ms
INFO: Process project properties
INFO: Process project properties (done) | time=91ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=289ms
INFO: Project key: sam-terminal.SONAR.sam-terminal-app
INFO: Base dir: C:\tools\GitlabRunner\builds\ybdPSipn\0\sam-terminal\terminal-app
INFO: Working dir: C:\tools\GitlabRunner\builds\ybdPSipn\0\sam-terminal\terminal-app\.sonarqube\out\.sonar
INFO: Load project settings for component key: 'sam-terminal.SONAR.sam-terminal-app'
INFO: Load project settings for component key: 'sam-terminal.SONAR.sam-terminal-app' (done) | time=69ms
INFO: Load project branches
INFO: Load project branches (done) | time=32ms

....

INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarqube4.devops.xxxxx.de/dashboard?id=sam-terminal.SONAR.sam-terminal-app&branch=main
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report

We are using self managed sonarqube instance (Community EditionVersion 9.9.1 (build 69595)) by our company.

Can somebody help what I’am doing wrong ?

@fza

Is main your main branch?
Updating the project name works only on the branch marked as main for the project.
If it is your main project could you please send us the verbose level logs?

Add /d:"sonar.verbose=true" to the…

  • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
    • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
1 Like

Hi Csaba,
yes main is our main branch. Verbose logs attached.
sonar_logs.txt (674.7 KB)

BR,
Ferruh

Hi Caba,
have you analyzed the logs. Any ideas ?

Hi @fza
Thanks for providing the logs and sorry for not getting back to you sooner.
I am taking over this investigation.
From the logs, we can see that the scanner is being executed in the context of a branch named bugfix/sonarqube_wrong_projectkey.

14:09:23.661 DEBUG: POST 200 https://sonarqube4.devops.xxxx.de/api/ce/submit?projectKey=sam-terminal.SONAR.sam-terminal-app&projectName=sam-terminal-app&characteristic=branch%3Dbugfix%2Fsonarqube_wrong_projectkey&characteristic=branchType%3DBRANCH | time=248ms
14:09:23.672 INFO: Analysis report uploaded in 267ms
14:09:23.696 DEBUG: Report metadata written to C:\tools\GitlabRunner\builds\ybdPSipn\0\sam-terminal\terminal-app\.sonarqube\out\.sonar\report-task.txt
14:09:23.696 INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarqube4.devops.xxxx.de/dashboard?id=sam-terminal.SONAR.sam-terminal-app&branch=bugfix%2Fsonarqube_wrong_projectkey

As Csaba mentioned, the -n: parameter is only taken into account when the analysis is executed for your main branch.
Can you please try to run an analysis for the main branch with the -n: parameter, and let me know if the name is correctly updated on SonarQube?

Thanks,
Antonio

Hi Antonio,
with the main branch same identical behaviour. The project is not renamed. New logfile is attached.

Thanks,
Ferruh
sonar_logs.txt (695.3 KB)

Hi @fza,
I am really sorry for the delay: it fell through the cracks :frowning:

At the time, I looked into the logs but couldn’t find any clues to help understand the misbehavior. I also tried to reproduce the issue locally, but my attempts were unsuccessful, most likely due to the differences in structure between my test projects and your projects.

I’d like to ask whether you have tried to rename the project again since then. In the meantime, we have released a new major version of the Scanner for .NET and new versions of SonarQube, which may have fixed your issue.

Thanks for your input and again apologies for the late reply,
Antonio