I have been reading the documents (SonarQube) and general Internet, I don’t know where else to look to troubleshoot and if I am missing additional runtime parameters
It looks like you might have missed that we have specific support for Jenkins to auto-detect the PR context and set the scanner parameters for you. It depends upon usage of the Bitbucket Branch Source plugin on the Jenkins side, as the link mentions.
Also note that in SonarQube 8.4, there’s been additional improvement to help automate the setup of Bitbucket-based projects to ensure everything is correct. Since you haven’t gotten this working yet, you might consider upgrading to 8.4.1 and then trying this using the new project wizard.
It does. But the configuration of that decoration is made easier on the Jenkins side if you use a combination of a standard branch source plugin for your particular ALM in conjunction with our plugin.
Thanks for confirming; what I am trying to make clear is that if you additionally use the Bitbucket Branch Source plugin and define a multibranch pipeline, the configuration of branch/PR parameters will be done automatically for you.
With that approach (multibranch pipeline) we are completely dependent on Jenkinsfile to identify branches and PRs whereas currently we have the flexibility to scan any repo using generic webhook on jenkins for invoking SQ builds
Okay, I was trying to make suggestions that might ease the burden of configuration, but since none of them sound appealing to you, we’ve got to troubleshoot it the way you’re doing it now.
Can you do the following?
Toggle the log level to DEBUG (in Administration/System)
Perform the PR analysis again, capturing the output as well as the command run itself with all parameters
Attach both the ce.log from your SonarQube server as well as the analysis log from your Jenkins build run to this thread?
I noticed the reason why you’re not seeing PR decoration in the log:
2020.08.03 14:03:58 DEBUG ce[AXO0otThVyNarV3RsenZ][c.s.C.D.A.A.C] Unable to contact Bitbucket server: 404 com.atlassian.bitbucket.commit.NoSuchCommitException Commit '3f94e086e71ce68b1a604f0446a44d0601614a82' does not exist in repository 'agency-settings-binder'.
2020.08.03 14:03:58 DEBUG ce[AXO0otThVyNarV3RsenZ][c.s.C.D.A.D] Failed to create Bitbucket Server Quality Report for commit SHA '3f94e086e71ce68b1a604f0446a44d0601614a82'
My guess is that Jenkins has checked out something that doesn’t exactly correspond to the latest commit on the PR branch; they need to match up.
You need to figure out the commit for the actual PR.
We had to add this to really make it work:
In Jenkisfile, when you do checkout, you would need to so something like this:
def scmVars = checkout scm
scmVars.GIT_BRANCH should be populated at this stage (or get it by some other means).
Now you can get PR hash:
def git_pr_hash = sh(
script: “git rev-parse origin/{GIT_BRANCH}",
returnStdout: true
).trim()
Now, pass git_pr_hash to scanner on analysis:
withSonarQubeEnv('sonarqube') {
sh """
{scannerHome}/bin/sonar-scanner \
-Dsonar.scm.revision=${git_pr_hash}
“””
}
This way sonarqube will match PR hash with Bitbucket server.
Then I goto SQ via that link and review and you see analysis of the PR (all the relevant information there). One thing I noticed in the Code Section its empty.
I goto to the See the PR link - it links back to Bitbucket/PR and review the code and nothing is added