How To Setup CI/CD Pipeline For Your .NET Azure Function

A quick tutorial on how to deploy your .NET Azure Function to the world

Jonathan Kristanto
Bina Nusantara IT Division
5 min readDec 20, 2021

--

CI CD lifecycle and Azure Function logo

Introduction

To give you a little summary, Azure Function is a server-less application platform which you developer to run a small piece of code (a.k.a function) on the cloud. If you want to know what Azure Function is and have a hands on you can learn about it through this article by Jeff Brown.

Prerequisites

This tutorial is intended for you people who are developing applications using Azure Function and want to figure out how to deploy the code you have. For starter you need to have :

  1. Azure DevOps account
  2. Azure Portal account
  3. Azure Function projects that are stored in Azure Repos
  4. Azure Subscription
  5. Function App instance

So without further ado let’s dive into the tutorial

Configure the CI Pipeline

Continuous Integration (CI) is responsible to merge code changes to the central repository. CI automates the process of building and compiling your projects and create the artifact (output of the build process that will be used to deploy your application to the server).

  1. Access the Pipeline menu from the sidebar and then click New Pipeline

2. Use the classic editor to configure the pipeline

I prefer to use the classic editor since it has a graphical user interface

3. Select the repository you want and if you have multiple branches, change the default branch to the one in sync with your stage of deployment

Example for deployment in the Dev Environment

4. The beauty of using classic editor is it already provides us with the template we can use for deployment. In this example, I use .NET as the application framework so select Azure Function for .NET template.

5. The template will provide us with 3 default steps, which is Build Project, Archive Files, and Publish Artifact: drop. If you have some custom Nuget package you used in your projects, you can add 1 more step which is dotnet restore

Add new .NET Core task
Change the command to restore, specify the path to your project, and give the path to your Nuget.config

6. In the Build Project task, you can specify the Path to Project(s) to specify which project you want to build. By default the CI Pipeline will build all *.csproj in your repository. However, if we have multiple projects in a single repository we can define which projects will be build.

For example, my project structure looks like this :

There are 2 projects available in this repository, which are the FrontEndAPI and BackEndAPI. If you want to just deploy one of the projects you can specify it in Path to Project(s) argument

9. To enable CI, go to the Trigger menu and check the Enable Continuous Integration option. If you want to specify which change will trigger the CI you can also set it in the Path Filter arguments.

Specify which folder of your project will trigger your CI Pipeline to run

This is the final structure of our CI Pipeline

Final CI Pipeline Structure

Your Azure Function CI Pipeline is ready now. Save the pipeline and queue. When your build is finished you will be notified via email

Configure the CD Pipeline

Continuous Deployment is responsible to automate the entire software release process. The CD Pipeline will handle infrastructure provisioning and deployment, and all the run is fully logged and visible to the entire team.

  1. Access the Release menu from the sidebar and click New Release Pipeline

2. Use the Deploy a function app to Azure Function template

Azure DevOps provide us with a lot of templates for deployment

3. Select the artifact we want to deploy. Artifact is generated from the CI pipeline

4. Configure the deployment parameters. The parameters are:

  • Azure Subscription
  • App Type (on Windows or Linux)
  • App Service Name (this is from the Function App instance. We will not cover how to create a function app in this tutorial but you can learn more about it through this article by Jeff Brown)

5. Select the agent pool & agent specification. I recommend using the latest agent specification to avoid agent deprecation (I have experienced it once and you need to manually change all the pipeline 🥲)

Your CD Pipeline is now ready to be used. Save the pipeline and create a release

To make sure your Azure Function has been deployed successfully you can check the function status on the Azure Portal.

Summary

In this tutorial, you have learnt how to set up CI/CD Pipeline for your .NET Azure Function. To recap what we have done:

  • We have configured the CI Pipeline with all the necessary parameters and learnt how to add a custom task
  • We have configured the CD Pipeline with all the necessary deployment and agent parameters

You now have a guidebook to use when you want to deploy .NET Azure Function. Hope you learn something new today and this tutorial can help you! Stay awesome, stay curious

--

--