In the deploy dacpac step in VSTS, you can set the database to only run based on custom conditions. The conditions examples are based on VSTS build information, and I can't find any documentation on using conditions from a connected Azure subscription or dacpac metadata. In the conditional page, they have a version variable which seems like it might be useful, but I can't find other information about it.
Basically, when the dacpac step is triggered, I want to check metadata against existing data, conditionally run the build step, and update metadata. Is this possible through a VSTS build step?
Yes, it is possible. You can add an user defined variable (such as the variable
result
with default value0
) in the VSTS build definition. And with the value1
to run the dacpac step, with value0
to skip the step.Detail steps as below:
Add a PowerShell task with two operations before the dacpac step:
Check if there has new changes for the existing data.
If the metadata only stored in Azure, you can refer this way to connect with Azure in powershell. If the metadata also stored in the repository (such as a git repo) you build with, you can also check the update in the repository.
Set the
result
variable value based on if there the metadata is updated or not.If the data is updated, then change the
result
variable with value1
:Else, do not change the value (keep the value with
0
)Since the data are managed in git VCS, you can check if the data is update or not in git repo. If the data is changed, then change the variable
result
as1
. detail powershell script as below:Set conditions for the dacpac step:
In the task, select Custom conditions for Run this task. If you want to run this task when succeeding and the variable
result
variable is1
, you can the express:Now if the
result
with the value0
, the dacpac step will be skipped, is theresult
with value1
, the dacpack will be executed.