Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Azure Function Build Release Pipeline in Azure DevOps CI/CD

DZone 's Guide to

Azure Function Build Release Pipeline in Azure DevOps CI/CD

Learn how to take your simple Azure Functions application and automate build and release processes.

· DevOps Zone ·
Free Resource

Image title


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. You can either create a new one in the Azure portal, or you can use any existing Azure functions available on the internet. For example you can see one here.

Setting Build Pipeline for Azure Function

Go to your Azure DevOps and click on Builds.

Image title

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

Image title


As my project is in Azure repository, I will select that. Please note 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.

Image title


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

Image title


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 have 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).

Image title


So I edited my code and build, and then initiate a manual build again. But even after that I was getting an error that read: "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."

Image title


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 being 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.

Image title


Now you should deselect the "Publish Web Projects" option.

Image title


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

Image title


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.

Image title


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

Image title


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.

Image title


Once it is created, you should see it 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.

Image title


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 look like this.

Image title


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.

Image title


Now you should set the artifact properties.

Image title


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.

Image title


The reason behind this is that your solution has many projects in it and each project will have 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.

Image title


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

Image title


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

Image title


Enabling Continuous Deployment

If you wish you can always enable 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.

Image title


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

Image title


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

Conclusion

In this article, we have learned,

  • How to configure Build Pipeline Configuration for Azure Function in Azure DevOps
  • How to configure Release Pipeline Configuration for Azure Function in Azure DevOps
  • About fixing errors in Pipeline configurations in Azure DevOps
  • How to enable Continuous Delivery/Deployment in Azure DevOps
  • How to enable Continuous Integration in Azure DevOps

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 share your feedback.

Topics:
devops ,cloud ,azure functions ,ci cd pipeline ,automation

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}