Unable to deploy Azure Function ZIP file through CLI command

410 Views Asked by At

I had developed azure function with private endpoint(disabled public access) HTTP Trigger using .NET Core C#.

Since inbound traffic for function , storage is cut off with internet access, I published my ZIP to a storage account(Newly created apart of storage that linked to function app and public enabled) via build(CI) pipeline and fetching the same ZIP file in release pipeline to deploy.

ZIP_URL : I can see ZIP URL with SAS token attached in logs.

I tried below commands for ZIP deployment in Azure CLI Task but none are helping me. So i tried to run locally in my machine and getting different issues as shown below respectively.

Command 1:

az webapp deployment source config-zip --name demo-funcapp-test --resource-group osh-poc-rg --src $ZIP_URL

enter image description here

Command 2:

az functionapp deployment source config-zip -g osh-poc-rg -n demo-funcapp-test --src $ZIP_URL

enter image description here

Command 3:

az webapp deploy --name demo-funcapp-test --resource-group osh-poc-rg --type zip --src-url $ZIP_URL --async false

enter image description here

Command 4:

az rest --method PUT --uri https://management.azure.com/subscriptions/55555c7b-1f7a-43a1-a90f-dee45a2f6262/resourceGroups/osh-poc-rg/providers/Microsoft.Web/sites/demo-funcapp-test/extensions/onedeploy?api-version=2022-03-01 --body "{'properties': {'type': 'zip','packageUri': '${ZIP_URL}' }}"

enter image description here

Updated: After creating VM with same VNET as function app and modifying agent to Self host, I successfully abled to deploy but functions are not showing in Azure Portal. enter image description here

1

There are 1 best solutions below

0
On

I finally understood the root cause of issue.

The problem lies in zip file that build through CI pipeline. The zip file folder structure is incorrect.

ZIP file and folder structure before Issue fix: The azure function app code files resides inside build folder that downloaded build.zip artifact from build pipeline as show in below screenshot.

Azure CLI task in unable to parse and deploy ZIP file, I see below log information in release logs file.

Bad Request({"error":{"code":"BadRequest","message":"System.ArgumentException: Invalid '/home/azureadminuser/myagent/_work/r1/a/_POCPrivateEndpoints-CI/drop/build.zip' packageUri in the JSON request\r\n   at Kudu.Services.Deployment.PushDeploymentController.<PushDeployAsync>d__16.MoveNext() in C:\\Kudu Files\\Private\\src\\master\\Kudu.Services\\Deployment\\PushDeploymentController.cs:line 474"}})

enter image description here

Changes done to CI pipeline:

using Pipeline Copy file task, I to make sure there is no build folder inside it.

enter image description here

Next In archive files Task i modified rootFolderOrFile to $(build.artifactstagingdirectory)/build

And it worked like a champ :)