Cut down time importing queries and/or copying dashboards in Azure DevOps

1k views Asked by At

I've spent some time getting a dashboard together on a project in Azure DevOps. I've got 14 queries backing it up, and 3 different widget types used. Brilliant. The issue I have is that I now need to roll this out to 70+ projects.

I exported all my queries using the WIQL marketplace extension but only seem to be able to import them into the other projects one at a time which is very time-consuming. I'm then needing to match the right query with the right widget in the dashboard, and again it's time-consuming. I've been looking for a way to copy dashboards but one doesn't seem to exist from what I've found.

Can anyone suggest a way that I can cut down the time for this? Even if it's just a way to get my queries across the different projects - that would be a huge time-saving.

I've tried Googling and YouTube as well, but seem to hit a brick wall - perhaps my search terms are wrong? - because I'm directed to pages and instructions on importing work items rather than queries.

2

There are 2 answers

2
Walter On BEST ANSWER

In addition to the python script and c# code shared in this ticket, you can also try to use REST API to copy dashboards. Here are the steps:

  1. Get a dashboard by its ID.

    GET https://dev.azure.com/{organization}/{project}/{team}/_apis/dashboard/dashboards/{dashboardId}?api-version=6.1-preview.3

  2. Copy the response body of the get dashboard REST API and delete the dashboard id.

enter image description here

  1. Create the supplied dashboard.

    POST https://dev.azure.com/{organization}/{project}/{team}/_apis/dashboard/dashboards?api-version=6.1-preview.3

Please paste the response body to the request body in this REST API. You only need to change the project name and team name here to copy to different projects. enter image description here 4.Currently, some widget settings may get null values , and you may need to manually configure them in new dashboards.

In addition, the product group is developing this feature. Here is the feature timeline. Please track and follow this ticket for latest updates.

0
Dejulia489 On

If you are familiar with PowerShell you can use AzurePipelinesPS to copy a dashboard or a query. The Copy-APDashboard and Copy-APQuery commands support cross collection and cross project copying.

Dashboard

The following will copy a dashboard into the same project as the source.

Copy-APDashboard -Name 'My Current Dashboard' -Session 'mySourceSession' 

The following will copy a dashboard into a different project in the same collection.

Copy-APDashboard -Name 'My Current Dashboard' -Session 'mySourceSession' -TargetProject 'Other Project Name'

Query

The following will copy a query named 'My Query To Copy' into the project named 'Project2'.

Copy-APQuery -QueryId 'Shared Queries/My Query To Copy' -Name 'My New Query' -TargetProject 'Project2' -Session 'mySourceSession' 

See AzurePipelines Session Management for more details on how to create a session and save it for use in later PowerShell sessions

Note:

Copy-APDashboard does not copy the underlying queries, only the dashboard widgets and scope. You must copy the queries using Copy-APQuery.