Let's have a quick look on how you can create an Azure Function and setting up a basic Azure DevOps flow for CI / CD.
First you need to create a function, and for the purposes of this demo this is what's needed:
The very first step will be to create a function app from the Azure portal. In the Azure portal, select "Create a resource", search for Function App, create it and fill in all required field with appropriate values.
Fire up VS Code and add if you have not already added the Azure Function extension, this would be a good time to do it. Click on the Azure Icon on the left, click on the create project icon, select a folder and C#, then add a Http-trigger by clicking the new trigger -> HttpTrigger. The function will come in a very basic "hello world" flavor and we will keep it that way.
If you would like to know more check out the official documentation.
Still with me? Good.
So the very basic and test-less😱 build process will be:
- Publish/Create zip
- Publish Artifact/Drop off zip
Create a new build pipeline in Azure DevOps and select an Agent Pool. I went with "Hosted VS2017" out of old habit.
Add a .NET Core task with build as command to your newly created pipeline. I'm lazy so I'll just wildcard our single project and add
Next up add a new .NET Core task with Publish as command, set project path accordingly, uncheck "Publish Web Projects" and add
--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)
Almost done! (with this part at least). Now lets add a "Publish Build Artifacts" task and not do anything with it.
Save & Queue -> and nothing but green ✅, yes? Excellent!
So let's move on and create a release pipeline. Select "Azure App Service Deployment" as template. Add our newly created build pipeline as the artifact.
Make sure the CD trigger is enabled:
Fill out your stage task with the required information, select "Function app" as "App type".
Trigger your release and nothing but the color of green is accepted!
Head off to the portal again and see something like this:
With the help of my good colleague, Terje, we have created a repository
git clone https://github.com/novanet/Blog/tree/main/2018-11_AzureFunctionsAndDevOps
with a basic function and a yaml-file for the build.
That's it! I hope this will be of use if and when you're headed this way.