Task in azure pipeline to Import azure functions not updating

Viewed 73

We have created pipeline to deploy in Fucntion App using DevOps pipeline. In CD pipeline we have added first task to deploy to Function App which is successful. Second task was to import those functions in Function app to API. The below we tried :

enter image description here

It successfully Imported the function but the second time onwards its not updating the function. it threw error saying that "API with the same name already exists" Hence we referred one article and developed the below code: enter image description here

https://www.domstamand.com/automating-your-openapi-updates-to-api-management-through-your-cicd-pipeline/

For this we are getting error as Null value for $api.apiVersionsetID. We output the value of $api to confirm this is null indeed.

Is there a way to update the functions in the existing API, as and when new functions are deployed in function app?

Update: There is a third party task in the market place to implement that but our project doesnt want to use that. they prefer only Microsoft recommended tasks.

1 Answers

You are trying to create a new Api in APIM each time you run your script. Instead, you should check if the Api already exists and use that and only create a new Api the first time. So you could do something along the lines of:

try { #Try to get an existing Api
    Get-AzApiManagementApi -Context $context -ApiId $apiId
}
catch { #If the Api doesn't exist, create a new one (with whatever parameters you need)
    New-AzApiManagementApi -Context $context -Name $apiDisplayName -ApiId $apiId -Path $apimUrlSuffix -ServiceUrl $apimWebServiceUrl
}
Related