Friday, November 8, 2019

Setting up Multiple YAML Builds in the Same Azure Git Repo With Path Filters

Azure DevOps has mainly two ways of creating build definitions to build your code. You can use either classic editor or YAML scripts to create a build. You can write YAML scripts to create various types of builds according to your project requirements. This blog post explains how to write YAML scripts to setting up different YAML builds in the same repo.

Pre-requisites : Azure DevOps project with multiple solutions in the same repo

Let's get started.
  • We have two solutions in the Azure DevOps Repo. The solution files belong to ConsoleApp1.sln are inside ConsoleApp1 folder. There is another web solution, with all the files belong to WebApplication1.sln can setup inside WebApplication1 folder and UnitTestProject1 folder.

  • As we have multiple solutions in Azure DevOps repo, let's create YAML builds for these solutions.
  • To do that go to Azure DevOps builds and start new build pipeline creation process.
  • Select the relevant source control where you have the code.

  • Select the Repo from the second step
  • Select the relevant build from the list. We have ASP.Net solution in our Repo. Hence, we can select ASP.Net build from the list.
  • You can review the YAML file from the next step. Either you can modify the YAML file now or later according to your requirements.
  • So far, we have discussed how to create a new YAML build in Azure DevOps. Now, we can add and edit the YAML build files according to the requirements.
  • Add two YAML files to the Repo as explained before.Our requirement is for setting up two different YAML builds for the same repo. We have source code in the main branch. But if we need to trigger a build when only commits changes to the ConsoleApp1. Then, we can modify one YAML file as follows. It triggers the build once changes are committed to ConsoleApp1. If any changes done to the UnitTestProject1 and WebApplication1 projects, it is set to not to trigger the build.

  • We need to trigger a build using the other YAML file once changes done to the UnitTestProject1 or WebApplication1. So, can modify the second YAML file as follows.

  • Do changes to both solutions and commit changes to verify how YAML builds behave. After you committed changes to solutions, You would be able to see two builds have triggered.

This post explained how to create a multiple YAML builds for the same repo. We were able to learn how to create a YAML build using the wizard and do the modifications to the YAML build according to the project requirement, specially focused on triggers and path filters.

No comments:

Post a Comment