javamachr / sonar-gitlab-plugin

Add to each commit GitLab in a global commentary on the new anomalies added by this commit and add comment lines of modified files
GNU Lesser General Public License v3.0
121 stars 21 forks source link

Analysis failing on Pull Requests using community branch plugin + sonar-gitlab-plugin #8

Closed lucasoares closed 3 years ago

lucasoares commented 3 years ago

Hey guys.

I need help to get my CI pipeline working using both plugins we are recommending (sonar-gitlab-plugin and community-branch-plugin).

I also created this issue with more details: https://github.com/mc1arke/sonarqube-community-branch-plugin/issues/307

Since I don't know much about how the sonar maven plugin works I don't know exactly where is the problem.

I have a java project where I'm testing it. I also tried a non-multimodule maven project but no success:

{
"task": {
"id": "AXfKLZ_vnweK8xMDl5qf",
"type": "REPORT",
"componentId": "AXfKLZ_jnweK8xMDl5qe",
"componentKey": "com.foo.bar:ci-test",
"componentName": "CI Test",
"componentQualifier": "TRK",
"status": "FAILED",
"submittedAt": "2021-02-22T14:38:43+0000",
"submitterLogin": "admin",
"startedAt": "2021-02-22T14:38:45+0000",
"executedAt": "2021-02-22T14:38:46+0000",
"executionTimeMs": 666,
"logs": false,
"errorMessage": "File 'ComponentImpl{type=FILE, status=SAME, name='src/main/java/com/foo/bar/citest/api/UserApi.java', dbKey='foo.bar:ci-test:src/main/java/com/foo/bar/citest/api/UserApi.java', key='foo.bar:ci-test:src/main/java/com/foo/bar/citest/api/UserApi.java', uuid='AXfGmaz8XBzcLJ5XNzZ7', description='null', children=[], projectAttributes=null, reportAttributes=ReportAttributes{ref=3, scmPath='src/main/java/com/foo/bar/citest/api/UserApi.java'}, fileAttributes=FileAttributes{languageKey='java', unitTest=false, lines=27}}' has no source code (Visit failed for Component {key=foo.bar:ci-test:src/main/java/com/foo/bar/citest/api/UserApi.java,type=FILE}  located foo.bar:ci-test:src/main/java/com/foo/bar/citest/api(type=DIRECTORY)->foo.bar:ci-test:src/main/java/com/foo/bar/citest(type=DIRECTORY)->foo.bar:ci-test:src(type=DIRECTORY)->foo.bar:ci-test(type=PROJECT))",
"hasScannerContext": true,
"organization": "default-organization",
"pullRequest": "27",
"warningCount": 0,
"warnings": []
}
}

Any idea?

lucasoares commented 3 years ago

Just found the problem!!

The error message has nothing to do with the problem itself :(

I was using -Dsonar.pullrequest.branch=$CI_COMMIT_BRANCH but in Gitlab the variable for source branch in MR pipeline events is $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME hahaha