Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy to azure functions using powershell

Is there any way, I can deploy to azure functions using powershell scripts? CI will not work for us because we use octopus deploy to deploy to all of our production services. So it would be beneficial if there is a way to deploy using powershell scripts.

Thanks!

like image 200
Krishh Avatar asked Apr 19 '16 22:04

Krishh


People also ask

How do I use Azure function in PowerShell?

In the Azure portal, browse to your function app. Under Settings, choose Configuration. In the General settings tab, locate the PowerShell version. Choose your desired PowerShell Core version and select Save.

How do I publish a function app in Azure?

In this article you create a function app and related Azure resources. In Solution Explorer, right-click the project and select Publish. In Target, select Azure then Next. Select Azure Function App (Windows) for the Specific target, which creates a function app that runs on Windows, and then select Next.


1 Answers

You can deploy functions to Azure using the Kudu REST API. You can also see some code/samples of doing this in our templates repository. In this code sample, you can see how our test script calls out to the Kudu Rest apis to deploy a zip to the Function App.

The folder structure for functions is a function per folder. You need to deploy your Function folders to ./site/wwwroot on the Function App. You also need to add any app settings which might contain your secrets if you add any new bindings between updates.

The PowerShell code would look something along the lines of:

    $apiUrl = $config.scmEndpoint + "/api/zip/"
    if ($destinationPath)
    {
        $apiUrl = $apiUrl + $destinationPath
    }

    $response = Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $config.authInfo)} -Method PUT -InFile $zipFilePath -ContentType "multipart/form-data"
like image 89
Chris Anderson-AWS Avatar answered Oct 24 '22 21:10

Chris Anderson-AWS