Setting up uploads from TeamCity and GIT to register different branches

Following the aid I received in Using OpenJDK and newer version of .NET framework with Sonar Scanner, I have set up our TeamCity and Git environment to upload to a repository whenever we do a pull request in Github, using our existing automation in TeamCity. This works well, and our builds are uploaded to SonarCloud and registered, but we are registering an issue.

Our Github setup works with multiple main branches, allowing our developers to work on multiple releases concurrently, or perform bug fixes in older releases to be released with patches.
We would like to be able to see the results of the individual pull requests to our main branches, but all the pull request uploads in SonarCloud are being registered as coming from the same branch, despite being registered correctly in TeamCity. The branch they are registered as coming from are the one that is set as the main Github branch.

This is the sonar-scanner command that we use with sonar-scanner:

sonar-scanner.bat -D"sonar.organization=star-code" -D"sonar.projectKey=STAR-Code_Ydelsesudstilling" -D"sonar.sources=." -D"sonar.host.url=https://sonarcloud.io"

Do I need to change something in the sonar-scanner command, or change anything in my setup in SonarCloud? I have so far only imported the project.

Hey there.

It sounds like you need to properly implement branch analysis parameters and pull request analysis parameters. This means:

  • Only providing sonar.branch.* parameters when a non-PR analysis is being performed
  • Providing sonar.pullrequest.* parameters when a PR analysis is being performed
  • Deriving these parameters from the build environment, typically using environment variables available in your build environment.

SonarCloud has no first-party integration with TeamCity, but the SonarQube plugin that Jetbrains supports should help here, and also works with SonarCloud as far as I’m aware.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.