Projects named with an ID in SC when the branch is not Master (AZDO)

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps): AZDO;
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI): AZDO pipelines;
  • Scanner command used when applicable (private details masked): sonarcloud@prepare
  • Languages of the repository: Java (Maven);
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting): when running a pipeline for the first time, when scanning a branch that is not the Master, a new project is created using an ID as a name;
  • Steps to reproduce: run a AZDO pipeline with the sonarcloud@prepare stage in it; After this part a project with a ID name is created; if the branch is anyouther than the Master, it keeps the ID as project name.
  • Potential workaround: only run scans on Master branch.

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hello @Eidil,

I would like to clarify: when running this initial scan, are you passing the sonar.projectName parameter? Or are you leaving it blank? This might be configured on a per branch basis in your pipeline configuration.

Another idea to investigate: go to SonarCloud > your project > Administration > Background tasks > click on the 3 dots to the right of the 1st analysis > Show SonarScanner Context > look for sonar.projectName.

In fact, you could reproduce both cases: the case where you initially scan master and the case where you initially scan a different branch, and see the scanner context for each of them. This way you can check whether the sonar.projectName param is being sent or not in each of the cases.

Hi Andrés,

Thank you, I’ll reproduce these scenarios and send the evidence here soon.

Hi @andres ,

Here are the variables when runing on ‘main’ branch:

Project scanner properties:
sonar.exclusions=/*.spec.ts,/node_modules/**
sonar.host.url=https://sonarcloud.io
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.links.ci=https://dev.azure.com/xyzSCFI/CC/_build/results?buildId=
sonar.organization=xyzscfi
sonar.projectBaseDir=/home/vsts/work/1/s
sonar.projectKey=xyz-cc-angular
sonar.projectName=xyz-cc-angular
sonar.projectVersion=54051
sonar.scanner.apiBaseUrl=https://api.sonarcloud.io
sonar.scanner.app=ScannerCLI
sonar.scanner.appVersion=8.1.0.6389
sonar.scanner.arch=x86_64
sonar.scanner.bootstrapStartTime=1781897399239
sonar.scanner.location=
sonar.scanner.metadataFilePath=/home/vsts/work/_temp/sonar/.../report-task.txt
sonar.scanner.mode=cli
sonar.scanner.os=linux
sonar.scanner.reporttaskfile=/home/vsts/work/_temp/sonar/.../report-task.txt
sonar.scanner.sonarcloudUrl=https://sonarcloud.io
sonar.scanner.truststorePassword=******
sonar.scanner.truststorePath=/usr/lib/jvm/temurin-17-jdk-amd64/lib/security/cacerts
sonar.scanner.wasEngineCacheHit=false
sonar.scanner.wasJreCacheHit=MISS
sonar.sources=src
sonar.test.inclusions=**/*.spec.ts
sonar.tests=src
sonar.token=******
sonar.working.directory=/home/vsts/work/1/s/.scannerwork

And here are runing on other branch:

Project scanner properties:
sonar.branch.name=homologation/1.0.0
sonar.cs.opencover.reportsPaths=/home/vsts/work/_temp/TestResults/**/coverage.opencover.xml
sonar.exclusions=/home/vsts/work/_temp/TestResults/**/coverage.opencover.xml
sonar.host.url=https://sonarcloud.io
sonar.links.ci=https://dev.azure.com/xyzSCFI/CC/_build/results?buildId=
sonar.organization=xyzscfi
sonar.projectBaseDir=/home/vsts/work/1/s
sonar.projectKey=215b1482-c4f3-f793-955a-0a94a2003010
sonar.projectName=xyz.CC.Worker
sonar.projectVersion=51018
sonar.pullrequest.cache.basepath=/home/vsts/work/1/s
sonar.scanner.app=ScannerMSBuild
sonar.scanner.appVersion=11.2.1
sonar.scanner.bootstrapStartTime=1781621282000
sonar.scanner.dotnetDll=/home/vsts/work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/4.2.4/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll
sonar.scanner.location=/home/vsts/work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/4.2.4/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll
sonar.scanner.metadataFilePath=/home/vsts/work/_temp/sonar/.../report-task.txt
sonar.scanner.mode=dotnet
sonar.scanner.reporttaskfile=/home/vsts/work/_temp/sonar/.../report-task.txt
sonar.tests=
sonar.token=******
sonar.visualstudio.enable=false
sonar.working.directory=/home/vsts/work/1/.sonarqube/out/.sonar

Let me know if any other evidence is necessary.

Thank you.

From main:

sonar.projectName=xyz-cc-angular

From the other branch:

sonar.projectName=xyz.CC.Worker

This is another hint that supports the suspicion I told you in my other message: the property is being set differently depending on the branch, and it’s probably being set by your pipeline script on a per-branch basis. You should review your pipeline scripts to see where this is happening.

Hi @andres ,

In fact the examples are from different projects, but in various cases here I’m running the scan without having the projects created on SonarQube, and I’m passing the project-key variable directly in the scan (with the desired project name):

  • when I run the scan from the main branch, the project is created accordinly;
  • when I run the scan in any other branch, the project is created with a strange ID as a name;

That’s the scenario I’m facing here.

Thank you,

Okay, I think I see what’s going on. As per our documentation, when passing sonar.projectName via CLI, it’s only used if the analysis is running on the main branch. Otherwise, sonar.projectKey will be used as name. So in the example where you are having this issue:

sonar.projectKey=215b1482-c4f3-f793-955a-0a94a2003010
sonar.projectName=xyz.CC.Worker

I guess your project name ends up being 215b1482-c4f3-f793-955a-0a94a2003010, right? Is this something you are setting manually? It might also be getting picked up from maven props in pom.xml, such as artifactId.