Search code examples
sonarqubesonarqube-web

Automated creation of new dashboards in SonarQube


Is there a way to automate/script creation of new dashboards in SonarQube, either via the webservice api or some other means?

I have a need to create dashboards per future releases (Dashboard for Release 1, Dashboard for Release 2 etc) where each release is worked on as a Stream in RTC. This would be easier if the analysis was running against trunk, but this is not how the project is currently structured using a branch/stream strategy.

Currently, as we move to a new future release which is being worked on in a future Stream, I need to recreate an analysis job in Jenkins, and create a new Dashboard against that analysis.

The dashboards are configured with the same widgets each time, but pointing to a different analysis project/results.

Is there a way I can automate creation of a new Dashboard? I see there's a GET api/dashboards/show but what I'm looking for is an api to create, or clone from existing dashboard?

We're using SonarQube 5.1.


Solution

  • A project-level dashboard is a template that is filled with each project's data as you navigate to it. You create it once, and it applies to every project automatically.

    It sounds to me like you'll be analyzing the branches of a project. As long as you differentiate them by setting a unique sonar.branch value for each one, the rest should just work. Each branch will show up as a unique "project" in SonarQube - with all the same features, navigation, and yes dashboards as every other project.

    Note that there are two types of dashboards: global dashboards project dashboards. Correspondingly, there are two types of dashboard widget: global and project.

    You can put either type of widget on either type of dashboard, but if you put a project widget on a global dashboard, it will make you configure a project - because it can't just pick up which project it should show from context.

    Put it on a project dashboard, though, and it will automatically display data from the current project.

    To create a project dashboard in version 5.1.2, first navigate to a project, then More > Manage Dashboards. There, you'll be able to create, configure, and share project-level dashboards with project-level widgets that just automatically show data from the current project context.

    EDIT

    Note that dashboards were removed in 6.2, so the directions above are only relevant for versions earlier than that.