仅在自上次部署以来对其进行过修改的情况下,才通过VSTS部署dacpac [英] Deploy dacpac through VSTS only if it's been modified since last deploy
问题描述
在VSTS中的deploy dacpac步骤中,可以将数据库设置为仅根据自定义条件运行.条件示例基于VSTS生成信息,我找不到来自已连接的Azure订阅或dacpac元数据的有关使用条件的任何文档.在条件页中,他们有一个版本变量似乎很有用,但我找不到有关它的其他信息.
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.
基本上,当触发dacpac步骤时,我想针对现有数据检查元数据,有条件地运行构建步骤,并更新元数据.通过VSTS构建步骤可以做到这一点吗?
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?
推荐答案
是的,有可能.您可以在VSTS构建定义中添加用户定义的变量(例如具有默认值0
的变量result
).并使用值1
运行dacpac步骤,使用值0
跳过该步骤.
Yes, it is possible. You can add an user defined variable (such as the variable result
with default value 0
) in the VSTS build definition. And with the value 1
to run the dacpac step, with value 0
to skip the step.
详细步骤如下:
-
在dacpac步骤之前添加具有两个操作的 PowerShell任务:
-
检查现有数据是否有新更改.
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.
根据元数据是否已更新来设置result
变量值.
Set the result
variable value based on if there the metadata is updated or not.
如果数据已更新,则将result
变量更改为值1
:
If the data is updated, then change the result
variable with value 1
:
Write-Host ("##vso[task.setvariable variable=result]1")
否则,请勿更改该值(使用0
保留该值)
Else, do not change the value (keep the value with 0
)
由于数据是在git VCS中管理的,因此您可以在git repo中检查数据是否更新.如果数据已更改,则将变量result
更改为1
.详细的powershell脚本如下:
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
as 1
. detail powershell script as below:
$files=$(git diff HEAD HEAD~1 --name-only)
echo "changed files as below: $files"
if ($files -contains 'filename')
Write-Host ("##vso[task.setvariable variable=result]1")
为dacpac步骤设置条件:
在任务中,为运行此任务"选择自定义条件.如果要在成功时运行此任务,并且变量result
变量为1
,则可以表达:
In the task, select Custom conditions for Run this task. If you want to run this task when succeeding and the variable result
variable is 1
, you can the express:
and(succeeded(), eq(variables['result'], '1'))
现在,如果值为0
的result
,将跳过dacpac步骤,为值为1
的result
,将执行dacpack.
Now if the result
with the value 0
, the dacpac step will be skipped, is the result
with value 1
, the dacpack will be executed.
这篇关于仅在自上次部署以来对其进行过修改的情况下,才通过VSTS部署dacpac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!