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 Answers
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.
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)
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
This helped me to setup CI/CD for Azure Functions.
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:
- Check in your C# function to a Azure DevOps repo (or any repo).
- 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
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.
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.
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
functionappname.scm.azurewebsites.net
and check the bin folder structure – HariHaran