Setting up continuous deployment on an Azure Function app can save a lot of time, particularly if your development process follows small, agile deployments where you may deploy to your production environment multiple times a day or week.
In order to use Azure DevOps, you will need a Microsoft account, but I will assume you have one since we are deploying to an Azure Functions app in an Azure subscription.
In order to get started, we need to add a YML file to our project in the main Git branch.
This file needs to be named specifically for Azure DevOps to utilise it:
The below yml content is based on a Linux based function app, but there are comments made for changes required to publish to a Windows-based one.
The basic anatomy is:
Tell Azure which branch to run the logic on to publish
Create some variables so it knows which Azure subscription to connect to and which Function app to deploy to
Define which VM type to create
Use that VM to install a defined NodeJs version
Use the VM to run the npm commands to build the NodeJs project
Create a zip of the build files
Create an artifact of that zip file
Upload the zip file to the Azure Function App
variables:# Azure Resource Manager connection created during pipeline creation# Thai can be retrieved from within the Azure PortalazureSubscription:'00000000-0000-0000-0000-000000000000'# Function app name. Set this to the name of your function appfunctionAppName: 'my-function-app-name
# Environment nameenvironmentName:'my-function-app-name'# Agent VM image name. Change this to 'windows-latest' if your function app is a windows based app service.vmImageName:'ubuntu-latest'stages:-stage: Build
displayName: Build stage
inputs:versionSpec:'14.x'displayName:'Install Node.js'-script:| if [ -f extensions.csproj ]
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fidisplayName:'Build extensions'-script:| npm install
npm run build --if-present
npm run test --if-presentdisplayName:'Prepare binaries'-task: ArchiveFiles@2
displayName:'Archive files'inputs:rootFolderOrFile:'$(System.DefaultWorkingDirectory)'includeRootFolder:falsearchiveType: zip
displayName: Deploy stage
displayName:'Azure Functions App Deploy: my-function-app-name'inputs:azureSubscription:'$(azureSubscription)'# Set this to just 'functionApp' if your if app is windows basedappType: functionAppLinux
Now, every time you push a Git commit to the 'deploy' branch of your project Git repository, this yml file will execute to build your project and upload it automatically to your Azure function app.