Sonar Setup¶
Follow these steps to submit coverage reports and source code to SonarQube.
SonarQube setup¶
Add project¶
- In SonarQube's top navigation, select "Projects".
- From the "Create Project" dropdown menu in the upper right, select "GitHub".
- Search for the target repository, then select "Set up selected repository".
Set permissions¶
- Go to the target project in SonarQube.
- From the "Project Settings" dropdown menu in the upper right, select "Permissions".
- Grant team group all permissions to manage the project.
- Ask another group member to remove your specific user's permissions because you cannot remove yourself.
Get project key¶
- Go to the target project in SonarQube.
- Select "Project information" in the upper right and note the project key.
Gradle projects use this project key in their build.gradle.kts
file.
.Net projects use this project key as a workflow input.
Create quality gate¶
- Select "Quality Gates" from the top navigation.
- Select "DEFAULT QUALITY GATE" from the list of quality gates.
- Select "Copy" in the upper right.
- Name the new quality gate, e.g. the name of the team.
- Increase required coverage to 90%.
- Grant team group permission to manage this quality gate.
Apply quality gate¶
- Go to the target project in SonarQube.
- From the "Project Settings" dropdown menu in the upper right, select "Quality Gate".
- Always use a specific Quality Gate: the gate created in the previous step.
- Select "Save".
Repository setup¶
Apply Gradle project key¶
In a Gradle project's build.gradle.kts
file, set sonar.projectKey
to the key copied from SonarQube:
Apply .Net project key¶
In a .Net project's workflows, set sonar-key
to the key copied from SonarQube: