I’m staring a new thread here because the old one has hundreds of replies, is for the non cloud version, and there is no real conclusion of
a) if this is possible or not and
b) how to do it.
Can we assume from this discussion that sonarcloud only works with the master branch, and only works with PRs from the master branch? There appears to be no way to configure sonarcloud to work with another branch such as develop, and recognize PRs from that. I.e. there appears to be no way to tell sonarcloud that we want it to ignore master branch and only care about changes and PRs to develop (or staging in our case). Please could someone confirm if this is the case.
The problem is that when you run sonar maven tool on the develop or staging branch, or any PR branch from either of those branches, it ignores it in that neither the PR nor the branch show up in the UI under branches or pull requests (although it does show it under recent activity). If you manually add a branch by running the maven scan with the -Dsonar.branch.name=develop or similar, then in the UI, develop shows up under branches but still no PRs are shown under PRs no matter what you do, and is also marked as short lived. So this does not solve the problem.
UPDATE 1
We just tried another way.
In bitbucket, we changed the repos “main” definition to staging.
Then we deleted the project from sonarcloud, and added it back.
We checked out the staging branch, and ran the maven sonar command:
mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=ourProject_ourService
Without specifying sonar.branch.name or sonar.branch.target.
This created the branch in sonarcloud marked as main.
Then we tried to get a pull request recognized.
We created a branch from staging called feature/testFeature
, changed some files, committed it, pushed it back to bitbucket, then created a pull request.
Then we checked out the feature/testFeature
branch and ran the same command:
mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=ourProject_ourService
However, in the sonar UI, it showed no pull requests.
In the pull request page in bitbucket, it shows
Not analyzed on SonarQube Cloud yet…
So this doesn’t work.
We then decided to try something more desperate.
We did the same steps with a new test pull request branch, but this time we specified the branches in the maven command line like this:
mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=ourProject_ourService -Dsonar.branch.name=feaure/test2 -Dsonar.branch.target=staging
This also did not work.