Creating Custom SonarQube Image With Mule Plugin
In this article, we will create the Custom SonarQube Image with MuleSoft plugin to scan and analyze Mule 3/Mule 4 Code.
Join the DZone community and get the full member experience.
Join For FreeWhat Is SonarQube?
SonarQube is an open-source platform for continuous inspection of code quality. It is a universal tool to perform "Static Code Analysis".
SonarQube helps in below:
- Identify the Overall Code Coverage
- Identify the Coverage on the Latest Code
- Identify the Code smells
- Identify the Code Bugs
- Identify the Security Vulnerabilities
In this article, we will create the Custom SonarQube Image with MuleSoft plugin to scan and analyze Mule 3/Mule 4 Code.
Step 1: Download the MuleSoft plugin binary from the below location.
Step 2: Execute below command and create a jar file as a plugin.
xxxxxxxxxx
mvn clean package sonar-packaging:sonar-plugin -Dlanguage=mule
Step 3: Download the below rules for Mule 3 and Mule 4.
Step 4: Create a Dockerfile for the SonarQube with MuleSoft plugin.
xxxxxxxxxx
FROM sonarqube:7.9.4-community
COPY mule-validation-sonarqube-plugin-1.0.3-mule.jar /opt/sonarqube/extensions/plugins/
COPY rules-4.xml /opt/sonarqube/extensions/plugins/
COPY rules-3.xml /opt/sonarqube/extensions/plugins/
Step 5: Execute the below command to create the Custom image.
xxxxxxxxxx
docker build --tag=alawaniy/sonarqube-mule .
Step 6: Execute the below command to run the container.
xxxxxxxxxx
docker run -d --name sonarqube -p 9000:9000 alawaniy/sonarqube-mule
Step 7: (Optional) Shell into container to see if the MulePlugin has been copied to the extensions folder.
x
docker exec -it <<Container_id>> /bin/bash
Step 7: Open Browser and type URL http://localhost:9000 and login with default credentials.
User Name: admin
Password : admin
After Login , Go to Administration and you will see the Mule Tab under General Settings.
Step 8: Go to Administration -> XML and delete the .xml extension otherwise Code scanning will conflict .xml pattern with sonar.lang.patterns.xml and sonar.lang.patterns.mule
Step 9: Deploy your MuleSoft code with below mvn command and it will push the analysis to the SonarQube.
xxxxxxxxxx
sonar:sonar test -Dsonar.host.url=http://localhost:9000 -Dsonar.sources=src/
Step 10: Check the analysis.
Hope this helps.
Thanks. Keep learning.
Opinions expressed by DZone contributors are their own.
Comments