SonarQube report on E-Mail
Assume a scenario : If you are a Product Owner or Project Manager or Developer and all you want is whenever SonarQube performs code analysis, Developer/Manger/Product Owner should receive an analysis report on their mail. No one needs to go to Sonar server and analyse the report.
Solution : We will configure mail notification from SonarQube server so that whenever project analysis takes place, subscribed users or groups will receive notification of the project analysis report via email.
Prerequisite : Assuming SonarQube Server is running on your system if not you can follow my blog for setup- https://medium.com/@amitvermaa93/sonarqube-setup-windows-e6a6c01be025
Step 1. First lets add a User. First login as Admin > Click on Administration > Security > Users > Create User > Enter your details and correct email address to receive emails >Create
Step 2. If you want to make an Group and add the users to it then you can follow this step else you can skip. Go to Security > Groups > Create Group > Enter Name > Create
Add user to Group- Again go to Security > Users > Click icon in Groups Column in front of user to Update Group > Search for your group and select > Done
Step 3. Click on Administration > under Configuration > in General > scroll down for Email section . Configure as below(I am configuring with gmail)
Email Prefix — (Sonar Report) — prefix with mail subject
From Address — (abc@gmail.com) — mails will come from this address.
From Name — (SonarQube) — mails will come from this address name
Secured connection — (starttls)- can be ssl
SMTP Host — (smtp.gmail.com) — configure accordingly
SMTP Password — (***) — mail password
SMTP Port — (587) — 587 for starttls and 465 for ssl
SMTP User Name — (abc@gmail.com) — mail id
If you have configured mail correctly, you can test your connection with Test Connection by providing mail id. If configured right it will sent an test email on provided mail and notify you else it will prompt error message.
Step 4. Now logout with admin and login with newly created user and click on My Account from your account section top right corner as below.
Step 5. Click on Notification. For Overall notification you can opt as per requirement and for project specific you can search your project and configure (Let say there are 3 project running in this server you want Quality gate status for all three project- then setup overall notification and you need New Issues for your particular project- then setup notification per project)
To make it easy I have selected all options for a project.
Step 6. Now scan your project either from Jenkins integration or from Sonar Scanner— you will get emails on subscribed user mail. In below image I have received 2 mails, one is for Quality gate status change because earlier it was Green and after code scan it becomes Red(and I have configured on overall notification) another for new issue found for the code(as we configured in notification section above for particular project).