How to change main branch and how to get sonarcloud to recognize pull requests

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.

We cant find any way to get sonarcloud to recognize pull requests.

Hi,

No.

Which you then - per one of our many other discussions - renamed, right?

No. Of course not. In a CI it would work because the integrations - as I’ve told you repeatedly - pick up the relevant values from the env & pass them forward to analysis. If you insist running analysis manually, then you must also pick up those values and pass them forward manually.

 
Ann

Note, some of the integration options pickup the right values, such as bitbucket pipelines, but for the rest of us with an unsupported build system, we need to know the details as the are missing from the “wizard”. For example we use AWS codebuild and jenkins. To implement the pipelines on these, we need to know the specific parameters needed, there is no magic to do this for us unfortunately.

Hi,

Jenkins is a supported CI.

 
Ann