How to perform Serverless operations with Azure DevOps
Build and deploy Azure Functions with Azure DevOps
Azure Functions are great for running tasks on demand, like processing queue messages or resizing images. They can run serverless, which means that you can run them without having to configure and maintain infrastructure. And withAzure DevOps Pipelines, Microsofts' Continuous Integration (CI) and Continuous Deployment (CD) solution, you can easily compile your Azure Functions and deploy to the Azure.
In this post, we'll take a look at how we can use Azure DevOps Pipelines to easily build and deploy an Azure Function to the cloud.
If you want to follow along, you'll need the following:
An Azure subscription (If you don't have an Azure subscription, create afree account before you begin)
The first step asks you where your code is. Before we give that information, click on the link below that says "Use the classic editor" to switch to the visual designer. This is easy to start with and from there you can still go back into theYAML configuration if you want
Now tell it where your source code is. This can be inAzure Repos,GitHub or somewhere else. Select the right code branch and selectContinue
Next, you can select a build template to start from. There are many templates that come out of the box and you can also create a build pipeline from scratch. Scroll down to the template calledAzure Functions for .NETand selectApply
(Select a build template in the Azure DevOps portal)
You'll now see the build pipeline. It has steps to compile the code, package the resulting files and publish them to a drop location, so that they can be used by another process, like a release pipeline. This all works out of the box and you can configure it as you like and add steps to the pipeline. SelectSave and queueandSave and runafter that to save the pipeline and start the build process.
(Working build pipeline in the Azure DevOps portal)
Now that you have a working Continuous Integration (CI) pipeline that builds your Azure Function code, we will create a release pipeline that takes the result from the build and deploys that to Azure.
In the Azure DevOps portal, selectReleasesin the left menu
ClickNew pipelineto create your first release pipeline
The first thing that you'll see is theSelect a template blade. Here, you can select a template to create a release process for one of the stages in your pipeline. Find the template calledDeploy a function app to Azure Functionsand selectApply
Next, you'll be asked to provide anamefor the stage that you've just selected a template for. You can create multiple stages, like Dev, Test, Acceptance and production and deploy your application through all of them. You can even configure when a certain stage should start deploying and you can indicate that somebody needs to approve the deployment to certain stages. Fill in something like"Production".
Now click on the stage to drill down into it and configure its steps
(Release pipeline in the Azure DevOps portal)
We only have one step in the process and that isDeploy Azure Function App. Select the step
Select theAzure Subscriptionto use for the deployment. If this is the first time that you use this subscription with Azure DevOps, you need to selectAuthorizeto grant Azure DevOps permissions to use the subscription
Next, selectFunction App on WindowsforApp Type
ForApp Service name, select the App Service that you want to deploy your Function to
Go back to the stages by selectingReleasesin the breadcrumb menu andEditafter that
(Release pipeline in the Azure DevOps portal)
In the overview, click on theAdd an artifact tile, and select the results of the build process
Click on the lightning icon of the artifact to configure continuous deployment. This automatically starts a release when a build successfully finishes
Now selectCreate releasein the right-hand corner and selectCreateafter that, to start deploying the Function to Azure
You should see a message that says that your release has been created. Click on thelink to the releaseto see it running
(Release results in the Azure DevOps portal)
After a while, the release will be finished and your Function is deployed to the Azure Function in Azure.
You've just usedAzure DevOps pipelines to create a complete Continuous Integration (CI) and Continuous Deployment (CD) solution to deploy anAzure Function to Azure. This was incredibly easy and took just a couple of minutes to complete. You can see how powerful Azure DevOps pipelines is as you can easily point the pipeline to other source code, add more tasks to the pipelines or select other templates, and useYAML to create more advanced pipelines. To learn more, create a trial account today and go and check it out