How to finalize Sonarqube/Gitlab Integration?

I’m using Sonarqube 8.9 LTS (8.9.1 currently), and I’m trying to have Sonarqube comment my GitLab merge requests.

After setting up the configuration according to the documentation, here is what I have in web.log :

2021.11.15 11:20:17 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.s.a.c.g.GitlabHttpClient] get projects : [https://mygitlab.mycomp.fr/api/v4/projects]
2021.11.15 11:20:17 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.i.c.TaskRunner] Q10008 scheduled after   0 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:17 DEBUG web[][o.i.c.TaskRunner] Q10008 starting              : OkHttp ConnectionPool
2021.11.15 11:20:17 DEBUG web[][o.i.c.TaskRunner] Q10008 run again after 300 s : OkHttp ConnectionPool
2021.11.15 11:20:17 DEBUG web[][o.i.c.TaskRunner] Q10008 finished run in   1 ms: OkHttp ConnectionPool
2021.11.15 11:20:17 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.i.c.TaskRunner] Q10008 scheduled after   0 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:17 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.s.a.c.g.GitlabHttpClient] get current user : [https://mygitlab.mycomp.fr/api/v4/user]
2021.11.15 11:20:17 DEBUG web[][o.i.c.TaskRunner] Q10008 starting              : OkHttp ConnectionPool
2021.11.15 11:20:17 DEBUG web[][o.i.c.TaskRunner] Q10008 run again after 300 s : OkHttp ConnectionPool
2021.11.15 11:20:17 DEBUG web[][o.i.c.TaskRunner] Q10008 finished run in 429 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:18 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.i.c.TaskRunner] Q10008 scheduled after   0 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:18 DEBUG web[][o.i.c.TaskRunner] Q10008 starting              : OkHttp ConnectionPool
2021.11.15 11:20:18 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.s.a.c.g.GitlabHttpClient] get projects : [https://mygitlab.mycomp.fr/api/v4/projects]
2021.11.15 11:20:18 DEBUG web[][o.i.c.TaskRunner] Q10008 run again after 300 s : OkHttp ConnectionPool
2021.11.15 11:20:18 DEBUG web[][o.i.c.TaskRunner] Q10008 finished run in 362 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.i.c.TaskRunner] Q10008 scheduled after   0 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[][o.i.c.TaskRunner] Q10008 starting              : OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[][o.i.c.TaskRunner] Q10008 run again after 300 s : OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[][o.i.c.TaskRunner] Q10008 finished run in 275 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.s.a.c.g.GitlabHttpClient] verify write permission by formating some markdown : [https://mygitlab.mycomp.fr/api/v4/markdown]
2021.11.15 11:20:20 DEBUG web[AX0hmd5Lq7nLRYn1AAB3][o.i.c.TaskRunner] Q10008 scheduled after   0 <C2><B5>s: OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[][o.i.c.TaskRunner] Q10008 starting              : OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[][o.i.c.TaskRunner] Q10008 run again after 300 s : OkHttp ConnectionPool
2021.11.15 11:20:20 DEBUG web[][o.i.c.TaskRunner] Q10008 finished run in 405 <C2><B5>s: OkHttp ConnectionPool

No warning, no error, but my merge request is still uncommented. I suspect the “auto-magic parameters” which are supposed to be set by “Branch Source plugin” (cf end of Pull Request Analysis | SonarQube Docs) are not set, but how can I check this ?

Also if they are not set, what would be the way to get them ? Is there some plans for Sonarqube to be compatible with “https://plugins.jenkins.io/gitlab-plugin/” much more popular than “https://plugins.jenkins.io/gitlab-branch-source/” ?

Thank you !

I’ve set up missing vars explicitely, and I still see no comment on my Gitlab merge request, and no warning/error in web.log :

In Jenkinsfile :

                withSonarQubeEnv(credentialsId: "token-sonarqube", installationName: 'si-devops-sonarqube.mycomp.fr') {
                    sh "./mvnw sonar:sonar \
                    --settings .devops/mvn_settings.xml \
                    --batch-mode \
                    --define sonar.pullrequest.key=${gitlabMergeRequestIid} \
                    --define sonar.pullrequest.branch=${gitlabSourceBranch} \
                    --define sonar.pullrequest.base=${gitlabTargetBranch} \
                    --define sonar.projectKey=myproject \
                    --define sonar.projectVersion=${params.releaseVersion}"
                }

In Jenkins logs :


./mvnw sonar:sonar --settings .devops/mvn_settings.xml --batch-mode --define sonar.pullrequest.key=8 --define sonar.pullrequest.branch=feature/change-to-merge --define sonar.pullrequest.base=feature/merge-request-decoration --define sonar.projectKey=myproject --define sonar.projectVersion=N/A

So what I’ve found is logs about this are mainly in ce.log, not web.log. After checking ce.log, all is fixed (projectId was wrong) and mr decoration works.

It would still be interesting to be able to remove :

                    --define sonar.pullrequest.key=${gitlabMergeRequestIid} \
                    --define sonar.pullrequest.branch=${gitlabSourceBranch} \
                    --define sonar.pullrequest.base=${gitlabTargetBranch} \

If u look for those gitlab-plugin variables like you are already looking for gitlab-branch-source variables.

1 Like

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