14
votes

I've got a solution that contains a web app and class libraries. I added two Azure function projects to this, the first is version 1 and the second version 2. Both run fine locally. This code is in an online repository (Visual Studio Online, now Azure DevOps), and I set up continuous deployment from it to an Azure function set up in the portal. However, neither project is showing up under Functions in the portal although the code deployed successfully just like Azure websites and the URL says "Your Function App is up and running". I'm using Visual Studio 2017.

7
How did you deploy the Function ? There are numerous ways to deploy the functions like runfromZip , zipDeployment etcHariHaran
@HariHaran Hi, thanks for your comment, I pushed the code base from Visual Studio to Azure DevOps, then synced the Function to DevOps. Just the same as continuous integration with an Azure Website.nmit026
Which pipeline task did you use ? Navigate to the functionappname.scm.azurewebsites.net and check the bin folder structureHariHaran
@HariHaran Used Kudu deployment, managed to make it work by publishing directly from Visual Studio, will do some more testing using test projects to get continuous deployment working.nmit026

7 Answers

3
votes

If you have'nt managed to get CD working, here's the trick. You mentioned that you are using Runtime V2 (.NET CORE ). I have some functions setup in CI/CD as well. In the Build Pipeline Build you function project with dotnet Build Task and point it with only the Function project path.

enter image description here

And in the arguments of the task add this /p:DeployOnBuild=true /p:DeployTarget=Package;CreatePackageOnPublish=true

After the build task, use the Publish Artifact task by default it outputs eveything to $(Build.ArtifactStagingDirectory) enter image description here

Now the last step. Use the Azure App Service Deploy task and Authenticate with your credentials like subscription,RG etc.

Now in the App Service Type choose FunctionApp on Windows/Linux ( your choice)

Now in the Package or Folder argument provide $(Build.ArtifactStagingDirectory)/YourFunctionProjectName.zip

enter image description here

This helped me to setup CI/CD for Azure Functions.

2
votes

While I found @HariHaran's answer helpful, it didn't exactly address my particular problem. Here's the solution I found using a Pre-Compiled Azure function:

  1. Check in your C# function to a Azure DevOps repo (or any repo).
  2. Use the following pipeline steps

npm install

  • Working Folder: $(System.DefaultWorkingDirectory)

dotnet build

  • Arguments: --configuration Release

Archive files

  • Root folder: $(System.DefaultWorkingDirectory)/bin/Release/netcoreapp2.1
  • Archive type: zip
  • Archive file to create: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip)
  • Replace existing archive: true

Note your root folder structure may be different for the path to your /bin folder. Adjust accordingly.

Azure Function App Deploy

  • (Select your subscription, app type and name)
  • Package or folder: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip

The key here for me was to understand that pre-compiled Azure functions require a specific folder structure, as defined here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library#functions-class-library-project. Getting the folder/file structure is necessary to allow your functions to show in the Azure portal.

Therefore my structure in the /wwwroot folder looked something like this:

 | - bin
 | - MyFunction
 | - host.json
1
votes

I had this same problem with a .Net Framework on Azure Functions version 1. I fixed it by specifying the proper root folder for the zip file creation: bin/release/net471

1
votes

Yet another solution for not showing (deploying) functions - in the CD pipeline "Azure Functions App Deploy", the "Deployment method" was set to "Auto-detect". Changing it to "Zip Deploy" fixed the issue.

What it did technically:

Deleting App Service Application settings. Data: ["WEBSITE_RUN_FROM_ZIP","WEBSITE_RUN_FROM_PACKAGE"]
Updated App Service Application settings and Kudu Application settings.
Package deployment using ZIP Deploy initiated.

When "Auto-detect" was enabled:

Trying to update App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"}
Deleting App Service Application settings. Data: ["WEBSITE_RUN_FROM_ZIP"]
App Service Application settings are already present.
Package deployment using ZIP Deploy initiated.
0
votes

I think your function is not getting deployed to the correct path in Azure. Check scm/Kudo to verify if it is deployed correctly.

0
votes

Sort of a mess, haven't tested thoroughly, but I managed to deploy it. I deleted the Version 1 Function project, made sure the portal environment was Version 2, disabled continuous deployment, and published manually from Visual Studio. Apart from SCM/Kudu, the folder structure appears to be the same. Not sure which of these did the trick, just glad for now it's working.

0
votes

When archiving try pointing to publish output folder instead of the root folder. For instance, if the build output folder is set to "publish_output" (--output publish_output --configuration Release) then try to archive the "publish_output" folder, not the entire root folder.

So that when deploying azure function our source package will have only the published output, not the entire folder. Below is a sample to deploy function app using az.

az functionapp deployment source config-zip -g $rg_name -n "$(fnapp_name)" --src $srcpkgpath