DEV Community

Sanjeevi Subramani
Sanjeevi Subramani

Posted on • Originally published at lkgforit.com on

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

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"

Enter fullscreen mode Exit fullscreen mode

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)

Enter fullscreen mode Exit fullscreen mode

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.

Enter fullscreen mode Exit fullscreen mode

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)

Enter fullscreen mode Exit fullscreen mode

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**

Enter fullscreen mode Exit fullscreen mode

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)

Enter fullscreen mode Exit fullscreen mode

Discussion (0)