which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube Enterprise Edition Version 7.9.5 (build 38598)
what are you trying to achieve
After GitHub PR is built and sonar-scanner finished successfully , I’d like to see the SonarScan check result on GitHub Checks tab
what have you tried so far to achieve this
Sometimes the check result can show up correctly on the GitHub Checks tab; but sometimes the check result doesn’t show up despite the PR check record can be seen on SonarQube PR dashboard.
@Joe thanks for the tips, I’ll check with the IT to see if they can enable the debug/log for troubleshooting. Besides that, is there any other way that I, as a sonarqube client user, can do while waiting for IT’s support?
Hi @Libra_Huang: without more evidence to find a pattern for why you are encountering these issues, I can’t determine a workaround. You can disable the quality gate but I wouldn’t suggest that. I would just forego the PR decoration for now.
The IT team provides some warning messages for my Jenkins PR build.
Pull request decoration did not happen. No commit found for revision '9209dd8446b16e96f3f48122a915f851aabff8b8'. Please pass a valid commit revision to the scanner using 'sonar.scm.revision' parameter.
It turns out the problem is related to how Jenkins merge/build PR branch and how sonar-scaner determines the commit sha value.
def get_pr_commit():
# Jenkins merges target branch to the PR before build.
# In order to make SonarQube PR decoration works, we need the PR commit head before merge
latest_commit = subprocess.check_output('git rev-parse HEAD', shell=True).strip()
if os.environ['GIT_COMMIT'] == latest_commit:
# PR branch is up-to-date with base branch, no merge commit was added
return latest_commit
else:
prev_commit = subprocess.check_output('git rev-parse HEAD^', shell=True).strip()
return prev_commit
Thanks for the update. We do have a section in our documentation regarding Jenkins setup. See Jenkins: Detecting changed code in Pull Requests. You may want to try adjusting your CI pipeline with our recommendation or you can follow your own pattern to determine the commit SHA value.
We decide to continue with “Merging the pull request with the current target branch revision” approach so the build/test can help discover problems if the code is merged. It would be great if Jenkins could preserve the PR commit head and save the workaround burden. Thanks.