Configuring the sonarqube gitlab plugin, preview mode - gradle

I am trying to configure the Gilab Sonar Plugin, so we can get sonar review comments in merge requests.
We have configured our gradle project, as per documentation and through gitlab-ci.yml, we call sonarqube task:
# Run sonar feature analysis
sonar_feature:
stage: sonar
only:
- /^BE-*/
tags:
- gitlab-runner-docker
script:
- ./gradlew sonarqube -Dsonar.analysis.mode=preview
-Dsonar.gitlab.project_id=${CI_PROJECT_PATH}
-Dsonar.gitlab.commit_sha=${CI_COMMIT_SHA}
-Dsonar.gitlab.ref_name=${CI_COMMIT_REF_NAME} -Dsonar.verbose=true
The 'sonarqube' task completes in gradle, but an 'external' job remains in running status, without completing . In Sonarqube itself, I don't see a new background task, so it seems analysis is not really occurring and it's a hanging/waiting mode.
Notes:
1. We don't see logging on the sonar_feature job, eventhough sonar.verbose=true.
What could be the issue?

I had the same problem when I had not configured sonar.gitlab.user_token.
Generate a User Token in GITLAB and add it to your sonar properties

Related

Jenkins Maven Job should fail when Sonar does not meet quality gate

i got a Maven Jenkins Job (not a Pipeline job) which runs a code analysis with sonar (mvn sonar:sonar). The Sonar report is create and everthing is fine. Now I want that the Jenkins job fails or at least gets a warning state if Sonar does not reach the quality gate.
I running Jenkins ver. 2.176.3.
How do I config the job? I only found a solution for a pipeline job with SonarQube (https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/)
Thanks ...
Found a solution.
https://github.com/jenkinsci/sonar-quality-gates-plugin/blob/master/README.md
Just install the plugin and add as Post Build Step "Quality Gates SonarQube Plugin".

Generating code coverage reports on Azure DevOps with Gradle 5.X

I'm trying to upgrade my project to Gradle 5.6.2. One of the tasks that I run on Azure DevOps is:
- task: Gradle#2
displayName: 'Test Project'
inputs:
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx7000m'
sonarQubeRunAnalysis: true
sonarQubeGradlePluginVersion: 2.6.2
testRunTitle: $(DISPLAY_NAME)
codeCoverageToolOption: JaCoCo
publishJUnitResults: true
testResultsFiles: '**/build/test-results/test/TEST-*.xml'
tasks: "test -Dtest.profile=unit --parallel"
After upgrading to Gradle 5.6.2 I get the following error when the code coverage reports are run:
Could not find method destination() for arguments [/home/vsts/work/1/s/batch/build/jacocoHtml] on Report html of type org.gradle.api.reporting.internal.TaskGeneratedSingleDirectoryReport
According to this answer, some changes were made to the reporting API in Gradle 5.X. Is the version of JaCoCo that's used on Azure Devops incompatible with Gradle 5.X? If so, is there anything I can do about this?
Some changes were made to the reporting API in Gradle 5.X, Is the version of JaCoCo that's used on Azure Devops incompatible with Gradle 5.X?
See this pull request: JaCoCo compatible with gradle 5.x. Last month, we raised a pull request to improve our Gradle task script since the feature has changed in Gradle 5.x(see this changes):
Also, the PR has been merged successfully. In one word, now, for our Gradle task, the Jacoco version is compatible with Gradle 5.x which has upgrade the new syntax.
To solve your issue, I suggest you'd better follow the solution which in the link you shared in question, to ensure the script of your build.gradle file is similar as the below format:
destination file("$xx/xxx/xx.xml")
Also, you can check this thread.

Difference between Sonarqube & SonarScanner

I'm using sonar & Jacoco for my Android application code coverage reporting. I could be successfully deploy it by setup jacoco task job & Sonar job & then following command.
./gradlew clean jacocoTestReport (name of jacoco task)
./gradlew sonarqube (<- mark this)
Report is successfully generated and showing to localhost:9000 sonar server setup.
I heard about sonar-scanner which is available to perform same task.
My confusion is what I should use sonar-scanner or sonarqube with gradlew command; How they mutually different from each other.
SonarQube is the central server holding the results of analysis.
SonarQube Scanner / sonar-scanner - performs analysis and sends the results to SonarQube. It is a generic, CLI scanner, and you must provide explicit configurations that list the locations of your source files, test files, class files, ...
SonarQube Scanner for Gradle / ./gradlew sonarqube - performs analysis and sends the results to SonarQube. You don't have to provide explicit configurations that list the locations of your various types of files because it gets that from your Gradle project.

SonarQube Maven Analysis is not available in jenkins job UI

versions:
jenkins: 1.651.1
sonarqube: 6.0
jenkins plugin "SonarQube Scanner for Jenkins" 2.3
manage jenkins: section sonarqube instance config:
sonarqube runner configs:
I only see MSBuild scanner in build-step config of a job:
I suspect this is due to old version of jenkins and old jenkins sonarqube scanner plugin. Can you please confirm. Or I missing something here?
As stated in the docs, you're going to use a standard Maven step for this.

How to launch a Grade SonarQube analysis with help of the Jenkins SonarQube plugin

I have installed Sonarqube plugin in Jenkins and configurations are done for SonarQube and sonar-runner in Manage Jenkins->configure System.
I want to trigger analysis for Gradle project. I would like to know the steps to be followed.
The Jenkins SonarQube plugin only allows to easily launch some SonarQube analysis with help of SonarRunner or Maven. If you want to launch a SonarQube analysis with help of the Gradle SonarQube plugin (see the docs) you must manually configure your Jenkins job to execute 'gradle sonarqube'. Simple example for SonarQube with Gradle is provided here.

Resources