Azure DevOps YAML Pipelines – Building Database Projects
5 mins read

Azure DevOps YAML Pipelines – Building Database Projects

In previous blog posts, I explained how to automate the Database Project Build & Deployment process using Azure DevOps (Release) Pipelines. These blog posts focused on setting up as easily as possible using the Classic Editor.

In this blog post, I’m going through the steps of setting up a build pipeline using YAML.

Quick Overview

Why YAML?
Step-by-step Example
Important Notice

Why YAML?

We have been creating our deployment pipelines with the classic editor. Why should we bother about YAML? YAML allows us to treat our build & release pipelines as code. As a result, we can also include our pipelines in source control.

Step-by-step Example

In this step-by-step example, we are going to automate our build process first by using YAML.

As a first step, we navigate to the Pipelines section in Azure DevOps. As a next step, we choose New at the right top corner.

Screenshot from application » 18
Azure DevOps Pipeline – New Pipeline

Now, we need to specify where our Database Project source code is hosted. In my case, I choose Azure Repos Git, and I select my AdventureWorks repository.

Screenshot from application » 19
Screenshot from application » 20

To continue, we need to configure our pipeline. We are starting from a Starter pipeline.

Screenshot from application » 21

As a first step, I rename the .yml file to ci-development-azuresql. Afterwards, we will start to create our first YAML Pipeline.

Before configuring our pipeline, we need to clean up the default pipeline. To get this done, we remove all the lines of code after the steps: syntax.

Screenshot from application » 22
The result after removing the lines of code

To continue, we will change the vmImage from ubuntu-latest to windows-latest. Then, we click beneath steps: in the YAML file. To make our life easier, we can now start to use the assistant to create the YAML Pipeline.

Screenshot from application » 23

Now we can follow the steps we have been discussing in a previous blog post, Automate your Database Builds – Using Azure DevOps Pipelines. I’m only including the URL as a reference. We will be going through the steps below since we will be making a minor adjustment.

So as a first step, we will be adding the Visual Studio Build task, then the Copy File task and to finalize we add the Publish Pipeline Artifact task (which differs from the task we have been using in the mentioned blog post).

Visual Studio Build Task

As mentioned earlier, we are using the assistant. So we open the assistant and search for Visual Studio Build Task.

Screenshot from application » 24

As soon as we choose the task, we can start to change the configuration. As you can see in the screenshot on the right, I change the Solution property from **\*..sln to **\*.sqlproj.

We are making this change because if you are creating a Database Project in another tool than Visual Studio (Azure Data Studio for example), you will not have a .sln file.

To finalize, we click the Add button at the bottom. As a result, you will see the following code in the YAML file:

Screenshot from application » 26
YAML Code – Visual Studio Build Task

Copy File Task

It is time to add the Copy File task, same drill, we open the assistant and search for the Copy File task.

Screenshot from application » 27

Now, we configure which files need to be included in our pipeline artifact. To minimize the size, we will only be including the .dacpac file. If you don’t specify, it includes all files.

During the configuration, we will use a couple of variables to define the source and target folder.

Screenshot from application » 28

After we add this to our YAML file, the following result is generated:

Screenshot from application » 29
YAML Code – Copy Files Task

Publish Pipeline Artifact Task

The final step is to add the Publish Pipeline Artifacts task.

Screenshot from application » 30

During the configuration, we need to specify the source directory and the Artifact name. As you can see we need to use the same variable that we used as a Target Folder in the Copy File task. Finally, we provide a name for our Artifact and we add the task to the YAML file.

Screenshot from application » 31
Screenshot from application » 32

Finally, we are going to adjust the trigger in the YAML file. We are changing the trigger from master to development.

Screenshot from application » 33
Screenshot from application » 34

By making this change, we actually tell the pipeline that it needs to execute every time a change is made to the development branch.

We have now successfully created our YAML Build Pipeline. To finalize we can save and run the Pipeline. We will be asked to provide a Commit message and where we want to add the pipeline. We will be saving the pipeline directly into our master branch.

You can find the example YAML file on my GitHub repository: blogging/Azure DevOps/Pipelines

Important Notice

We have created this YAML Build Pipeline manually from scratch. Which allowed us to gather some insights into YAML.

If you already have existing Pipelines in Azure DevOps, you can easily generate the YAML code for these Pipelines. Unfortunately, this does not work for Release Pipelines.

If you are running into an issue with the vmImage, this blog post might help you: Visual Studio Build in Azure DevOps Pipelines failing on latest Windows vmImage

If you want to learn about YAML, I used the following resources to learn:

One thought on “Azure DevOps YAML Pipelines – Building Database Projects

Leave a Reply

Your email address will not be published. Required fields are marked *