integrating gitlab with sonarqube
Solution 1
- You should use -Dsonar.gitlab... instead of -Psonar.gitlab... etc. (see https://groups.google.com/forum/#!topic/sonarqube/dx8UIkcz55c )
- In the newest version of the plugin you can enable to add a comment when no issue is found. This helps with debugging.
@1: The comments will be added to your commits and will then show up in the discussion section of a merge request
@2: We are running a full analysis on master and a preview on any branches.
Solution 2
I had the same problem than yours. Comments were not showing in the GitLab MR. I made it work with two fixes:
- make sure the preview mode is used. If it is not, the issues are not reported to GitLab
- for issues to appear as GitLab comments, they have to be "new" issues. If you launched an analysis of your project before pushing to GitLab, the issues will not be considered as new by SonarQube, and no comment will be added to the MR.
If this does not solve your problem, try cloning the plugin repo, adding traces to the code (CommitIssuePostJob.java is the place to look), package the jar with maven and deploy the patched jar to your Sonar installation. That is how I saw that I had no new issues to report.
Related videos on Youtube
aver
Updated on March 22, 2020Comments
-
aver over 4 years
I have GitLab CE (v8.5 at least) installed on my server. I would like to integrate it with sonarqube so that merge requests shows any issues in the comment section. Has anyone integrated these 2 systems successfully?
At the moment, only sonarqube plugin I found is the following but I'm not able to successfully integrate it with GitLab.
https://gitlab.talanlabs.com/gabriel-allaigre/sonar-gitlab-plugin
I used a docker container for sonarqube (v5.5) and copied the plugin into extensions directory. Configured gitlab user token and gitlab uri in the plugin's setting page in sonarqube.
I'm using GitLab CI for continuous integration and I have the following build job for sonarqube (using gradle)
sh gradlew sonarqube -Psonar.analysis.mode=preview -Psonar.issuesReport.console.enable=true \ -Psonar.gitlab.commit_sha=$CI_BUILD_REF -Psonar.gitlab.ref_name=$CI_BUILD_REF_NAME \ -Psonar.gitlab.project_id=$CI_PROJECT_ID
But, I'm not sure what to after this. Couple of questions:
What happens when a merge request does not exist yet? In my git workflow, users will submit a merge request after they're done working on their branch. So, how will this plugin know which merge request to update?
Right now I have the sonarqube valiation task set to be running only on master branch. I think this will need to be changed to user branches too, right?
I did try submitting a merge request, but I didn't see any comments being added. I think I'm missing some configuration or a process. Really appreciate if you can help point me to the right direction.
-
floer_m almost 8 yearsAre you sure the GitLab plugin has really installed to SonarQube? (One way to validate: When you go to Administration in SonarQube, do you see GitLab in the left-hand side?) I ask because like you, I was running SonarQube with Docker ... note this caveat: if the
extensions/plugins
directory is aVOLUME
, then you can't expect towget
orcurl
into it from yourDockerfile
. You may think you grabbed the extension, but if youls
after startup you may find, the plugin is not really there -
aver almost 8 yearsThanks for your reply. I checked Administration in Sonarqube and verified that the plugin actually shows up. After I pulled the sonarqube docker image, I actually copied the plugin files inside the container.
-
Alexandre FILLATRE over 7 yearsI got the same problem. Were you able to find a solution ?