all Technical posts
Deploy Swagger API to Azure API Management using TFS Build
This blog post describes how you can automatically update your Swagger definition in Azure API Management with TFS Build.
We would like to automate the import Swagger API functionality in Windows Azure API Management management portal. You could to this manually using the following screen:
There are Azure Commandlets for Azure Management API but there is currently a bug. When using the “Import-AzureApiManagementApi” command it is not possible to replace the API definition in Azure API Management (this is possible in the portal, but not in the PowerShell cmdlet).
But no worries, we can still use REST and invoke the REST API from powershell (as supported in PS 5.0) ourselves.
Enable Rest API
First we will enable REST API on Azure Management Service. Go to API Management, navigate to Security and select “Enable API Management REST API”.
Generate an Access Token
Next, generate an Access Token and copy the complete string so we can use it later. Also copy the name of your management API tenant (in upper left corner).
Create the following PowerShell build script and do a check-in on source control
Add a build step to your build definition
Next, we will configure our build and add an extra deploystep to deploy to Azure Management API.
Select a PowerShell script by navigating to Utility
Drag the task just after the Azure Web App Deployment. You might have noticed that there is a sleep of 15 seconds in the PowerShell script. This is because our website will need some time to startup. We could always move the API deployment step a bit further in the build chain but we don’t want to have our API and Azure Management API out of sync that long.
Select the script from source control and enter the parameters.
The PowerShell parameters are:
-link “link to swagger url” -tenantName “api mgmt tenant name” -sas “shared access key”
And we should get a successful build after queueing a new one.
Wonderful, one step less to worry about when deploying!!
Subscribe to our RSS feed