Skip to content

JanneMattila/azure-api-management-developer-portal-import-and-export-scripts

Repository files navigation

Azure API Management Developer Portal Import and Export scripts

Introduction

Developer portal has examples how to migrate portal between services however it might be process that does not work for everybody. Example was built in mind that you migrate the content from source to target in same flow. This means that if done in e.g. Azure DevOps Pipelines then you would have to have access to both systems at the same time. To separate these two process steps these PowerShell helper scripts has been developed:

  • Export-APIMDeveloperPortal
  • Import-APIMDeveloperPortal

Names should pretty well describe the actual intent of the scripts.

Export-APIMDeveloperPortal exports the developer content to filesystem. This requires only access rights to the source environment (e.g. Service Principal executing the export in Azure Pipelines).

Import-APIMDeveloperPortal imports content from filesystem. This requires only access rights to the target environment.

You can use these scripts for this kind of process:

  • Export developer portal in pipeline
  • Store exported developer portal to Azure Artifacts or Pipeline Artifacts
  • Import developer portal in your pipeline using above artifacts

Usage

Export

.\Export-APIMDeveloperPortal.ps1 -ResourceGroupName rg-apim -APIMName contosoapi -ExportFolder Export

This creates Export folder and exports developer portal content and media files from contosoapi APIM Developer portal.

Import

.\Import-APIMDeveloperPortal.ps1 -ResourceGroupName rg-apim -APIMName contosoapi -ImportFolder Import

This load content and media files from Import folder and imports them to contosoapi APIM Developer portal.

Example implementation in Azure DevOps

You can implement this process in few different ways but here's one example implementation:

  • CI for exporting the content from developer portal
    • Store export as artifact
  • CD for importing the content to developer portal

Idea is that you manually trigger the CI when you want to export the content out from the developer portal.

Export using CI

Azure DevOps CI for developer portal export

CI PowerShell configuration

Relevant yaml portions of the configuration:

- task: AzurePowerShell@5
  displayName: 'Azure PowerShell script: FilePath'
  inputs:
    azureSubscription: 'AzureDev'
    ScriptPath: 'Export-APIMDeveloperPortal.ps1'
    ScriptArguments: '-ResourceGroupName apim-rg -APIMName demo -ExportFolder $(Build.ArtifactStagingDirectory)\Export'
    azurePowerShellVersion: LatestVersion
    pwsh: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: Export'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)\Export'
    ArtifactName: Export

That build should now have artifact correctly stored in it:

CI artifact

Import using CD

Importing the developer portal

Release Definition

Relevant yaml portions of the configuration:

- task: AzurePowerShell@5
  displayName: 'Azure PowerShell script: FilePath'
  inputs:
    azureSubscription: 'AzureDev'
    ScriptPath: '$(System.DefaultWorkingDirectory)/source/Import-APIMDeveloperPortal.ps1'
    ScriptArguments: '-ResourceGroupName apim-qa-rg -APIMName demo-qa -ImportFolder $(System.DefaultWorkingDirectory)/CI/Export'
    azurePowerShellVersion: LatestVersion
    pwsh: true
    workingDirectory: '$(System.DefaultWorkingDirectory)/CI/Export'

Credits

Special thanks to @MiikaAntila for helping out finalizing and testing these scripts.

About

Azure API Management Developer Portal Import and Export PowerShell scripts

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published