1. Add jacoco plugin to your core project pom.xml so that Junit coverage report can be analysed by Sonarqube. The snippet is given at the bottom. in this article.
2. Go to Sonarqube -> Projects -> New Project -> Enter Project Name -> Generate a login token
3. Go to Jenkins -> Create a new Job
a. Fill Source Code Management section
b. Set Branches to build like */develop
c. Set Build Triggers as "Poll SCM" with following schedule (Check for git change every 15 mins)
H/15 * * * *
d. Check
f. In Build section, enter "pom.xml" and set goal as "clean install"
g. In post step, Set
h. In "Add Post Build Step" dropdown select "Execute SonarQube Scnanner" option
i. In the analysis property set as following:
sonar.login=yourlogin-token-from-step2-above
sonar.projectKey=your-project-name-from-step-2-above
sonar.java.binaries=core/target/classes
sonar.sources=core/src
sonar.tests=core/src/test/java
sonar.java.coveragePlugin=jacoco
sonar.coverage.jacoco.xmlReportPaths=core/target/site/jacoco/jacoco.xml
sonar.junit.reportPaths=core/target/site/jacoco/jacoco.xml
4. Once setup trigger the Jenkin job. Once build is successful, the code analysis will be sent to Sonarqube. Go to Sonarqube and check if a new project appears on your dashboard.
No comments:
Post a Comment