Azure API management Developer portal Migration/deployment using Azure Devops pipeline

Devops YAML Automation of APIM developer portal deployment | Deployment of managed portal using pipeline | URL links replacement foreach environment

Azure API management Developer portal Migration/deployment using Azure Devops pipeline
Sanjeevi Subramani's photo
Sanjeevi Subramani

Published on Jul 1, 2021

3 min read

Subscribe to my newsletter and never miss my upcoming articles

The new API management developer portal contains many customization options in the look and feel design option using the Paperbits Framework. You can learn more on that in the below article: Article.

We will see how to automate the APIM developer portal in this article using Azure Devops YAML pipeline.

First, we will install npm packages:

      - task: Npm@1
        displayName: Npm Install command
        inputs:
          command: "install"

With below code we can automate the APIM developer portal deployment from the source apim instance to the destination apim instance.

      - pwsh: |        
          node ./migrate --sourceSubscriptionId "$(sourceSubscriptionId)" --sourceResourceGroupName  "$(sourceResourceGroupName)" --sourceServiceName "$(sourceAPIMName)" --destServiceName "$(destinationAPIMName)" --destSubscriptionId "$(destSubscriptionId)" --destResourceGroupName "$(destResourceGroupName)" --sourceTenantid "$(sourceAzure_Tenant)" --sourceServiceprincipal "$(sourceServicePrincipal)" --sourceSecret "$(sourceAzureDevOps-ServicePrincipal-Secret)"  --destTenantid "$(Azure_Tenant)" --destServiceprincipal "$(ServicePrincipal)" --destSecret "$(AzureDevOps-ServicePrincipal-Secret)"
        workingDirectory: "$(System.DefaultWorkingDirectory)/scripts.v3"
        displayName: Run Migrate cmd from $(sourceAPIMName) to $(destinationAPIMName)

Below is the description of the parameters used above:

- destinationAPIMName - destination APIM instance name.
- destinationSubscriptionId - above destination apim's subscription id
- destinationResourceGroupName - above destination apims's resource group name
- destTenantid - destination tenantid
- destServiceprincipal - destination serviceprincipal or user name.
- AzureDevOps-ServicePrincipal-Secret - secret or password for service principal or az login for the destination.
- sourceAPIMName - source apim name.
- sourceSubscriptionId - above source apim's subscription id
- sourceResourceGroupName - above source apims's resource group name
- sourceAzure_Tenant - source tenant id.
- sourceServicePrincipal - source serviceprincipal or user name
- sourceAzureDevOps-ServicePrincipal-Secret - secret or password for service principal or az login for the source apim.

By using below code, we can replace any URL links used inside the developer portal by using string replace.

      - pwsh: |        
          node ./migrateenvurl --existingEnvUrls "$(existingEnvUrls)" --destEnvUrls  "$(destEnvUrls)" --destServiceName "$(destinationAPIMName)" --destSubscriptionId "$(destSubscriptionId)" --destResourceGroupName "$(destResourceGroupName)" --destTenantid "$(Azure_Tenant)" --destServiceprincipal "$(ServicePrincipal)" --destSecret "$(AzureDevOps-ServicePrincipal-Secret)"
        workingDirectory: "$(System.DefaultWorkingDirectory)/Pipelines/scripts"
        displayName: Update urls for $(destinationAPIMName)

In above code we must pass in comma separated source env URL links into existingEnvUrls field and destination env URLs links to destEnvUrls field in same order to replace them.

something sample like below:

    - existingEnvUrls - https://docs.microsoft.com/**en-us**/learn/modules/azure-compute-fundamentals/,https://lkgforit.com/how-to-use-paperbits-open-source-drag-and-drop-content-builder-and-free-website-generator-to-**3f94acd13aef**
    - destEnvUrls - https://docs.microsoft.com/ar-ar/learn/modules/azure-compute-fundamentals/,https://lkgforit.com/how-to-use-paperbits-open-source-drag-and-drop-content-builder-and-free-website-generator-to-**57408d333118**

In the above sample in existing env urls en-us link of msdocs is given first then comma separated by another url - these links are used in navigation inside the developer portal in design mode. These will be getting replaced in the destination apim developer portal with ar-ar url in destEnvUrls field first value and second value also same.

Please find the full pipeline code below:

name: CD-ApiMDeveloperPortal-Build

trigger: none

variables:
  - name: poolName
    value: "agentpoolName"
  - name: location
    value: West US

jobs:

  # All tasks on APIM Developer portal pipeline
  - job: Deploy_APIM_Developer_Portal
    displayName: Deploy APIM Developer portal from one APIM instance to another APIM instance Migration 
    pool:
      name: $(poolName)
    timeoutInMinutes: 90
    steps:
      - task: Npm@1
        displayName: Npm Install command
        inputs:
          command: "install"

      - pwsh: |        
          node ./migrate --sourceSubscriptionId "$(sourceSubscriptionId)" --sourceResourceGroupName  "$(sourceResourceGroupName)" --sourceServiceName "$(sourceAPIMName)" --destServiceName "$(destinationAPIMName)" --destSubscriptionId "$(destSubscriptionId)" --destResourceGroupName "$(destResourceGroupName)" --sourceTenantid "$(sourceAzure_Tenant)" --sourceServiceprincipal "$(sourceServicePrincipal)" --sourceSecret "$(sourceAzureDevOps-ServicePrincipal-Secret)"  --destTenantid "$(Azure_Tenant)" --destServiceprincipal "$(ServicePrincipal)" --destSecret "$(AzureDevOps-ServicePrincipal-Secret)"
        workingDirectory: "$(System.DefaultWorkingDirectory)/scripts.v3"
        displayName: Run Migrate cmd from $(sourceAPIMName) to $(destinationAPIMName)

      - pwsh: |        
          node ./migrateenvurl --existingEnvUrls "$(existingEnvUrls)" --destEnvUrls  "$(destEnvUrls)" --destServiceName "$(destinationAPIMName)" --destSubscriptionId "$(destSubscriptionId)" --destResourceGroupName "$(destResourceGroupName)" --destTenantid "$(Azure_Tenant)" --destServiceprincipal "$(ServicePrincipal)" --destSecret "$(AzureDevOps-ServicePrincipal-Secret)"
        workingDirectory: "$(System.DefaultWorkingDirectory)/Pipelines/scripts"
        displayName: Update urls for  $(destinationAPIMName)
 
Share this