We run this for both PR’s and commits to feature branches. In the case of a PR we are setting sonar.branch.name to the PR,ex. pull/10 and sonar.branch.target to the target branch, ex. release/1.0.
In the case of a commit to a feature branch the sonar.branch.name & sonar.branch.target are both set to the feature branch, ex. feat/1.0/123/CoolNewFeature.
We are expecting to get the analysis reports back into our GitHub PR’s with Quality gate for pass / fail for our GitHub status checks but we don’t get anything.
I created a new project and imported that from GitHub to Sonar cloud and ran the automatic analysis, and the new project seems to get something at least. For example if I try to add a Require status checks to pass before merging rule to a branch I can see SonarCloud Code Analysis as an option, where as we don’t get that with any of our other projects.
I’m pretty sure that we have done something wrong, but I’ve spent a couple days digging around and not finding the right answer, so I’m hoping someone with some more knowledge can help / point in the right direction.
Your assumption that the same properties shall be provided for branch analysis and pull request analysis (and decoration) is wrong.
For pull request you but provide 2 different properties (in replacement of sonar.branch.name and sonar.branch.target):
sonar.pullrequest.key: the number of the pull request
sonar.pullrequest.branch: the associated branch
Optionally sonar.pullrequest.base: the target branch if not the main branch
Okay I found the reason why the analysis is not being added to our PRs. We created the projects in sonar cloud via the CLI and the projects were not linked with our repos.
I’ve seen a few other threads of people with similar issues, and it looks like the only way to generate the link between the sonar cloud project and the GitHub repo is by importing via the UI. This is not scaleable. This will introduce a manual step every time we create a new repo.
Are there any plans to create the link via the cli or the api?