Search code examples
sonarqube

Is it possible to Import SonarQube rules?


We're transferring our CI stack from a consulting company to in-house. We need to export the SonarQube profiles from the consultant's SQ instance to our corporate instance. We can export the profiles but the consultants created hundreds of custom rules and when we try to import the profile it fails to import the custom rules. We found in the API where you can export the rules to a JSON file, but can't find documentation on how to import them.

Is it possible to import SonarQube rules? What is the best way to go about that?

Referenced documentation:
SQ Docs - Copying Quality Profiles:
https://docs.sonarqube.org/display/SONAR/Quality+Profiles#QualityProfiles-CopyaprofilefromoneSonarQubeinstancetoanother
StackOverflow - How to export Rules:
How to extract or export rules from SonarQube
SQ API - Rules: https://docs.sonarqube.org/pages/viewpage.action?pageId=2392166


Solution

  • It is not possible to import/export the logic of those custom rules, only their presence in a profile.

    In the case of rules coded in Java, you must make them give you at least the jar containing the rule implementations. Once you install that jar (and restart your server) the rules will be available to you.

    In the case of rules written in XPath, you must make them give you their XPath configurations, and you will need to re-create those XPath rules on your side (a tedious process of filling in a form once for each rule).