Search code examples
sonarqubesonarqube5.1sonarqube-web

Is it possible to update add a tag to a SonarQube rule or issue from within a plugin?


I'd like to tag certain issues as related in SonarQube. The rules are defined in various different repositories including the out of the box Java one.

I can manually add tags to rules through the api and any issues created from them will inherit the tag, but this is tedious.

Is it possible to add tags to existing issues or rules within a plugin in SonarQube 5.1? If so how?


Solution

  • First, don't forget that you can bulk edit issue tags via the interface. But that's not what you asked about. :-)

    The UI is based almost entirely on web services at this point, so if there's something you can do in the interface that you want to automate in some way, it's likely just a matter of finding the right web service. In this case, https://nemo.sonarqube.org/web_api/api/issues/set_tags is what you want and/or https://nemo.sonarqube.org/web_api/api/issues/bulk_change.

    I have the impression you may be after a one-time action here, so it's likely you can do what you want via the web services without having to write a plugin. That will let you edit existing issues. Future issues can be handled proactively by adding the tags to the relevant rules (https://nemo.sonarqube.org/web_api/api/rules/tags). As you said, new issues created from those rules will inherit the new tags.

    If for some reason you really want to write a plugin, then simply call the web services from it.