Site icon Sibeesh Passion

Azure Function Build and Release Pipeline in Azure DevOps CI CD

[toc]

Introduction

Playing with Azure Function is always a nice feeling, and it is very important to configure both build and release pipeline for all of your applications, Azure Functions are not different. In this article, we will see how we can create both build and release pipeline in Azure DevOps for our Azure Function application. I hope you will like it.

Prerequisites

You should have an Azure Function application to configure the build and release pipeline for the same. You can either create a new one in the Azure portal, or you can use any existing azure functions available in internet, for example you can see one here.

Setting Build Pipeline for Azure Function

Go to your Azure DevOps and click on Builds

Select Builds

Now you should see an option to select where your code is available. You can choose accordingly.

Select Code Source

As my project is in Azure repository, I will select that. Please be noted that I will be using the classic editor to create the pipeline now, so that I can show the steps with the screenshots. You should be able to see the final yml file at the end of the configuration.

Now you can select the template of your project, I will select .Net Core as the template as my Azure Function is in .Net Core.

Asp.Net Core as Template

Now you can see that our Pipeline is created with some default tasks and settings as follows.

Pipeline Taks
Pipeline Settings for Azure Function

As everything is already created for us, let us save and queue the build. Please make sure that your source code branch is valid and you had verified the build. I forgot to do this, and I was getting the below error, as there was some issue with my code (there was an additional dot(.) in my code, I added it by mistake).

Initial Build Error

So I edited my code and build, and then initiate a manual build again. But even after that I was getting an error as “No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory”.

Second Build Error

The reason for this is, that by default the “Publish Web Projects” is enabled in the Publish task. As ours is not a web project, and if this option is enabled the Publish task will look for a web project in the repository and run the publish command. If we have a web.config file or a wwwroot folder in the directory, it is been treated as a web project.

We have to disable this option as it is not applicable for our project, as it is not a web project. To do so, please go to your Publish task.

All Tasks

Now you should deselect the “Publish Web Projects” option.

Deselect Publish Web Projects

Now save your build configuration and queue a new build. If everything goes well, you should see that your build is successful.

Build Success

If you wish to see the YAML code of a task, you should be able to see it if you click on “View YAML” link.

Please do not forget to enable if you need to trigger the build automatically when there is a check in happened in the repository.

Enable or Disable Continuous Integration

Setting Release Pipeline for Azure Function

Now that we have got our build successful, let us go ahead and create a release pipeline for our Azure Function. But before we do that, we need to create a service connection in our Azure DevOps project. To create one, please go to your Azure DevOps projects settings -> Pipelines -> Service Connections.

Azure Resource Manager Connection

Once it is created, you should see the same under your service connections slab. Now go to the Pipelines section of your Azure DevOps project and click on Releases and the click on New pipeline and select Azure App Service Deployment as the template.

Azure App Service Deployment

You should see this task in the Task section of your pipeline. If you are unable to see the service connection that you had created on the right panel, just remove the task and add the same again and then check. Your task definition should be looking as below.

Azure App Service Deploy Task

Once you are done, save your pipeline. And before you create a release, make sure that you had assigned the right build artifacts. Click on Add an artifact.

Add an Artifact Option

Now you should set the artifacts properties.

Assign Artifacts Properties

Click on Add and Save your pipeline and then queue a release by clicking on the button Create release. You may get the error ” Error: More than one package matched with specified pattern: d:\a\r1\a\**\*.zip. Please restrain the search pattern” now.

Error

The reason behind this is, that your solution has many projects in it and each projects will be having its own zip folder in the artifacts, so to fix this we should specify our Azure Function Project in the Package section of our pipeline task.

Click on the Azure App service Deploy task and the go to the Package or Folder section and then click on the three dots.

Package or Folder Option

Now you should have an option to select the right zip file.

Choose the Right Zip File

Now Create the release again and you should see that the release is successful. You can also see my StackOverflow answer here.

Release Dev

Enabling Continuous Deployment

If you wish you can always enable the continuous delivery or deployment. This will trigger whenever there is a build. To set up this, please go to your Release pipeline and click on the trigger.

Continuous Deployment Trigger

Now you should see an option to enable the Continuous Deployment.

Enable Continuous Deployment

Now all you have to is change something in the code, and not worry about the build and releases. How cool that is?

Conclusion

In this article, we have learned,

Please let me know what else you had learned from this Article.

Your turn. What do you think?

Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.

Kindest Regards
Sibeesh Venu

Exit mobile version