SonarQube 6.4→6.7.2升级后邮件通知格式变更,如何恢复Severity展示?
Great question! This shift from severity-based to type-based issue grouping in email notifications was an intentional update in SonarQube 6.7 LTS and later versions. However, you can absolutely revert to the old 6.4-style format by customizing the email templates. Here's how to do it:
Step 1: Set Up the Custom Template Directory
First, create a dedicated folder for your modified email templates—SonarQube will automatically prioritize these over the default system templates:
mkdir -p $SONARQUBE_HOME/extensions/email-templates
Replace $SONARQUBE_HOME with the actual path to your SonarQube installation folder.
Step 2: Copy the Default Template to Customize
Next, copy the relevant template file from the default configuration directory to your new custom folder. For analysis completion notifications (the ones showing issue counts), you'll need the ce_task_success.ftl file:
cp $SONARQUBE_HOME/conf/email/ce_task_success.ftl $SONARQUBE_HOME/extensions/email-templates/
If you also need to adjust alert notifications (like when quality gates fail), repeat this step for the project_alerts.ftl file.
Step 3: Modify the Template to Display Severity Counts
Open the copied template in a text editor. Look for the section that groups issues by type—it will look similar to this:
<ul> <#list issueTypes as issueType> <li>Type ${issueType.name}: ${issueType.count}</li> </#list> </ul>
Replace that entire block with code that groups issues by severity instead:
<ul> <#list ["BLOCKER", "CRITICAL", "MAJOR", "MINOR", "INFO"] as severityKey> <#assign severity = issueStats.severities[severityKey]> <li>Severity ${severity.name}: ${severity.count}</li> </#list> </ul>
This loop will iterate through each severity level in the classic order and display the count for each, matching the format you had in SonarQube 6.4.
Step 4: Restart SonarQube
Save your changes and restart the SonarQube server to apply the new template. After the restart, any new analysis completion emails will use the severity-based grouping you configured.
Quick Notes:
- This customization is stable and will persist through future SonarQube updates (especially for LTS versions like 6.7.x, where template context variables rarely change).
- If you have other notification types that need the same adjustment, repeat the template modification process for their corresponding
.ftlfiles in theconf/emaildirectory.
内容的提问来源于stack exchange,提问作者jstanley

