GitHub pull request not decorated with SonarCloud results on first build

We have a GitHub repository and an internal Jenkins integrated with SonarCloud. On the first Jenkins build, when PR is not yet created, sonar task is executed with sonar.pullrequest.branch set to branch name and sonar.pullrequest.key set to null. When PR is then created, Sonar decoration is missing from it, and Jenkins build has to be restarted for it to appear. Is there any workaround for this? We would like to avoid restarting build on PR creation just for the SonarCloud results to appear.

Hello Cezary,

Thanks for reaching out and welcome to the community!

The GitHub decoration is created immediately after the analysis is completed. This decoration requires that the PR is already created and the correct pullrequest.key is passed, if this information is missing the decoration does not happen. I am afraid that there is no way to somehow delay the decoration until the PR is created.

What is a possible workaround is to analyze the branch for the first time without specifying the pullrequest.key and pullrequest.branch, just with sonar.branch.name. This will create a branch on the SonarCloud and the GitHub check on the commit (of course the code you are analyzing has to be in GitHub). Once the PR is open the check will be visible on the GitHub PR. Keep in mind you will not receive SonarCloud PR comment on the PR (just the check, after the first analysis). On top of that, in the SonarCloud, this branch will be visible in two places: “Short-Lived Branch” and if there was a subsequent analysis with correct PR parameters in “Pull Requests”. This may cause some inconsistencies and it is not recommended approach.

It is not possible in your case to first create the PR and then run the SonarCloud analysis?

Best,
Marcin

Hi Marcin,

Thanks for your answer. We would not want to go to anything fancy, and we would prefer to keep our integration with SonarCloud as vanilla as possible. I just hoped to check if maybe we’re missing something obvious. We can of course re-run builds once PR is created.

1 Like

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