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
Prerequisites
An existing Azure Functions App.
Create an Azure Function App through Code
Open Visual Studio 2017 and go to New -> Project.
Select Cloud => Azure Functions.
Click OK.
Select the HTTP Trigger Function. Click OK.
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)
Click on + New Project.
Click on "Create".
Now, we will commit our code into Azure Repos Git.
So, click on Repos from the left side menu.
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.
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
Now, check your Azure DevOps Project (Repos).
Build Pipeline For Azure Function
Now, click on Pipeline from the left-side menu.
Pipeline -> Build -> New Pipeline
Click on "Continue". Now, select a Template.
Select ASP.NET Core here and "Apply". Some default jobs will add.
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.
Enable "Continuous Integration".
Save it.
Queue your build.
Click on "Run".
Build Pipeline has been successfully completed. Now, it is time to create a Release Pipeline.
Release Pipeline for Azure Function
Select Pipeline -> Release.
Select the Azure App Service Deployment template and "Apply".
Here, select Azure Subscription, App Type, and App Service Name.
Save it and now click on “Add an Artifact”.
Click Add. In addition, save it.
Make sure that the Continuous Deployment is enabled.
Navigate to Functions App.
The function is deployed successfully
Now, copy the function URL and browse it.
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.
Commit your changes.
Now check you Build Pipeline.
Now check Release Pipeline,
Now check your function output by hitting function URL,
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