3

I'm setting up a deployment pipeline for a new Azure function that I'm creating. As we already use TeamCity and Octopus deploy at work for deployments, I'm thinking of using the KUDU REST API to deploy the Azure function as detailed here where the Powershell commands are run from Octopus deploy.

As Azure functions reside in an Azure function app and an app can have multiple functions, is it possible to just deploy one function within the app at a time?

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
dhughes
  • 645
  • 1
  • 7
  • 19
  • Is there a specific reason you ask or a problem you faced? – Mikhail Shilkov Jun 03 '17 at 06:24
  • 1
    Over time I see us adding more functions to the function application and as changes are made to individual functions, it would be good to be able to deploy only the function that changed. That way the scope of regression testing can be minimised. – dhughes Jun 03 '17 at 11:32

4 Answers4

4

I think @Mikhail's answer is more about "is it possible to have a function app with only one function?", while the question is probably more "is it possible to individually deploy a function even if there are already others?".

And the answer is that it is possible if you use the Kudu zip controller, since you can aim it at any folder you want. So if you deploy to /api/zip/site/wwwroot/MyFunc1/, you only affect that one function.

One thing to be aware of: the zip controller does not propagate deletions. So if you publish a file with a function, and later publish a new zip without it for that same function, the file will remain. msdeploy can be used instead as it supports this.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • Thanks David - you are correct - "is it possible to individually deploy a function even if there are already others?" is my question. I have updated the title to reflect this. – dhughes Jun 04 '17 at 07:19
0

Since you said that you are using Octopus Deploy, you could use Deploy web template step to deploy a single function. Just provide function name in the field where it asks for custom folder path.

Tany
  • 1,252
  • 14
  • 30
0

For anyone wanting to do this using a powershell script that calls the KUDU API and is executed by Octopus deploy you can follow the steps in my answer here (You can also refer to other answers on this question for some interesting approaches)

Here is the relevant portion for deploying only one function to a function app.

Get your publish profile username and password as described here

$creds = Invoke-AzureRmResourceAction -ResourceGroupName YourResourceGroup -ResourceType Microsoft.Web/sites/config -ResourceName YourWebApp/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force    
$username = $creds.Properties.PublishingUserName
$password = $creds.Properties.PublishingPassword

Invoke the Kudu REST API to push your function to the function app

$username = '<publish username>' #IMPORTANT: use single quotes as username may contain $
$password = "<publish password>"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

$apiUrl = "https://<yourFunctionApp>.scm.azurewebsites.net/api/zip/site/wwwroot"
$filePath = "<yourFunctionName>.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method PUT -InFile $filePath -ContentType "multipart/form-data"
S Raghav
  • 1,386
  • 1
  • 16
  • 26
-3

Yes, of course it is possible. Pretty much every Function App starts with just 1 function...

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107