Friday 10 August 2018

Bulk upgrade SPFx solution in multiple site collections using Microsoft Flow

I was recently working on an assignment where we set up an automated Site Collection provisioning process and developed several SPFx webparts. Each of the newly provisioned site collection would have these SPFx web parts provisioned on the pages of the site.

In the web part development process, we re-deployed the solution several times after the initial deployment. This was for the two scenarios below.



Changes made to the already deployed web parts :


When changes are made to the existing web parts which are already deployed to Site collection pages, the process of making updates available to these web parts is easy. Just update the SPPKG file in the App Catalog and replace the web part bundle files with the new build. Once this is done, the web parts in all the sites where the solution is deployed would get the updated functionality


New webparts added to the solution


If you have added new web parts to your SPFx project since the last release, the above process won't make these web parts available in the site collections where the solution was already installed.
In this case, we need to 

  • Increment the solution package version number
  • Redeploy the SPPKG file to App Catalog 
  • Update the web part bundle files in the CDN location 
  • UPGRADE the solution in the site collections.


When we have tens or hundereds of site collections where we need to upgrade the solution, manual upgrade is definitely not an option. We can automate this with a PnP PowerShell script using the "Update-PnPApp" command. 


https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/update-pnpapp?view=sharepoint-ps

In our case, the list of all the provisioned site collections was available in a SharePoint list column (part of provisioning process where users request for new site.)

Microsoft Flow came to the rescue - Read all the list items and for each site in the list, execute a REST API call using the "Send an HTTP request to SharePoint" action.


ALM API Endpoint to upgrade the solution is (https://docs.microsoft.com/en-us/sharepoint/dev/apis/alm-api-for-spfx-add-ins)

"_api/web/tenantappcatalog/AvailableApps/GetById('<GUID>')/Upgrade"

The GUID of the solution can be found using the PnP PowerShell Command. Connect to a site collection and run the command : Get-PnPApp
































Fast and easy !! Hope this helps.

No comments:

Post a Comment