SonarQube is a mainstream tool for continuous inspection of code quality, which can be used for static and dynamic analysis of code repositories. After SonarQube is integrated into pipelines, common code issues detected in running pipelines, such as bugs, will be displayed directly on the dashboard.
Click Log in in the upper-right corner and log in with the default account admin/admin.
Note
Depending on where the instance is deployed, you may need to set the necessary port forwarding rules and allow the port in your security group to access SonarQube.
Step 2: Create SonarQube Admin Token
Click the letter A in the upper-right corner, then select My Account from the menu to go to the Profile page.
Click Security and enter a token name, for example, kubesphere.
Click Generate and copy this token.
Note
As indicated, you cannot view this token again, so make sure you copy it successfully.
Step 3: Create Webhook Server
Run the following command to get the address of the SonarQube Webhook.
export NODE_PORT=$(kubectl get --namespace kubesphere-devops-system -o jsonpath="{.spec.ports[0].nodePort}" services devops-jenkins)
export NODE_IP=$(kubectl get nodes --namespace kubesphere-devops-system -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/sonarqube-webhook/
Expected output:
http://10.77.1.201:30180/sonarqube-webhook/
Click Administration, Configuration, and Webhooks to create a Webhook.
Click Create.
In the dialog box that appears, enter Name and Jenkins Console URL (i.e., the SonarQube Webhook address). Click Create to complete the operation.
Step 4: Add SonarQube Server to Jenkins
Run the following command to get the address of Jenkins.
export NODE_PORT=$(kubectl get --namespace kubesphere-devops-system -o jsonpath="{.spec.ports[0].nodePort}" services devops-jenkins)
export NODE_IP=$(kubectl get nodes --namespace kubesphere-devops-system -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
The Jenkins dashboard is installed by default when DevOps is installed. Additionally, Jenkins is configured with KubeSphere LDAP, meaning you can log in to Jenkins directly using your KubeSphere account (e.g., admin/P@88w0rd). For more information on configuring Jenkins, see Jenkins System Settings.
Note
Depending on where the instance is deployed, you may need to set the necessary port forwarding rules and allow port 30180 in your security group to access Jenkins.
Click Manage Jenkins in the left navigation pane.
Scroll down and click Configure System.
Search for SonarQube servers and click Add SonarQube.
Enter Name and Server URL (http://NodeIP:NodePort). Click Add, select Jenkins, and create credentials with the SonarQube admin token in the dialog box that appears (as shown in the second screenshot below). After creating the credentials, select them from the dropdown list next to Server authentication token. Click Apply to complete the operation.
Note
If the Add button does not work, go to Manage Jenkins > Manage Credentials and click Jenkins under Stores scoped to Jenkins. Click Global credentials (unrestricted) and then click Add Credentials in the left navigation pane. Add credentials with the SonarQube admin token as shown in the second screenshot below. After adding the credentials, select them from the dropdown list next to Server authentication token.
Step 5: Add SonarQube Configuration to DevOps
Run the following command to edit the ConfigMap devops-config.
kubectl -n kubesphere-devops-system edit cm devops-config
Add the field sonarQube after the devops section and specify host and token under it.
Create a SonarQube token so that the pipeline can communicate with SonarQube when running.
On the SonarQube console, click Create new project.
Enter a project key, for example, java-demo, and click Set Up.
Enter a project name, for example, java-sample, and click Generate.
After creating the token, click Continue.
Select Maven and copy the sequence number in the green box shown in the figure below. If you want to use it in the pipeline, you need to add this sequence number in credentials.
Receive the latest news, articles and updates from KubeSphere
Thanks for the feedback. If you have a specific question about how to use KubeSphere, ask it on Slack. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.