Azure DevOps - CI CD - Build And Release Pipeline - Azure Function

In this article, I am going to show how we can make a CI & CD Build and Release Pipeline for an Azure Function. Below is my process.
  • Code Repository = Azure Repo Git
  • Build Pipeline
  • Release Pipeline
  • Finally Azure Function in Portal with CI & CD 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Prerequisites
 
An existing Azure Functions App.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function

Create an Azure Function App through Code
 
Open Visual Studio 2017 and go to New -> Project.

Select Cloud => Azure Functions.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Click OK.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Select the HTTP Trigger Function. Click OK.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Leave everything as default. I just renamed the Function Name to (SayHelloFunction).
 
In addition, if we pass the Name as a query string, then the “Hello From Noida – Welcome – {Name}” Message will return.

Check-in Your Code to Azure Repos

 
Now, our Visual Studio Code is ready.
 
The next step is to create a project in Azure. Open here.
 
Log in with your credentials.
 
Create an organization here if you do not have.
 
I have rahsaxen1 (Organization)
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Click on + New Project.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Click on "Create".
 
Now, we will commit our code into Azure Repos Git.
 
So, click on Repos from the left side menu.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Copy the Azure Repo Git URL.

https://dev.azure.com/rahsaxen1/_git/RAHULTestFunctionAppCICD
 
Now, open your Functions App code location.
 
We will commit our code into Azure Repo Git through Git Command.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Type cmd.exe and hit Enter - the command window will open.
 
Execute the below Git commands.
 
> git init
> git add .
> git commit -am "Add your app"
> git remote add origin <git Repo Url>
> git push -u origin –all
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Now, check your Azure DevOps Project (Repos).
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function

Build Pipeline For Azure Function
 
Now, click on Pipeline from the left-side menu.
 
Pipeline -> Build -> New Pipeline
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Click on "Continue". Now, select a Template.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Select ASP.NET Core here and "Apply". Some default jobs will add.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Keep everything as default. Select Publish,
 
In Publish Job -> DeSelect Publish Web Projects because if this option is enabled, the Publish task will look for a web project in the repository and run the publish command.

Now, select the Triggers option.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Enable "Continuous Integration".
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Save it.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Queue your build.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Click on "Run".
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Build Pipeline has been successfully completed. Now, it is time to create a Release Pipeline.
 

Release Pipeline for Azure Function

 
Select Pipeline -> Release.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Select the Azure App Service Deployment template and "Apply".
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Here, select Azure Subscription, App Type, and App Service Name.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Save it and now click on “Add an Artifact”.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Click Add. In addition, save it.
 
Make sure that the Continuous Deployment is enabled.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Now, check in the Azure Portal.
 
Navigate to Functions App.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
The function is deployed successfully
 
Now, copy the function URL and browse it.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
The function access level is Function. So, while browsing, we have to pass the function code as well.
 
Now, make any change in your Visual Code and commit your changes. Automatically, the Build will trigger and deployment will happen.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Commit your changes.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Now check you Build Pipeline.
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Now check Release Pipeline,
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 
Now check your function output by hitting function URL,
 
Azure DevOps - CI CD - Build And Release Pipeline - Azure Function
 

Overall summary of this article

 
In this article, we learned the following -
  • Configure Build Pipeline in Azure DevOps
  • Configure Release Pipeline in Azure DevOps
  • Enable Continuous Deployment in Azure DevOps
  • Enable Continuous Integration in Azure DevOps