简体   繁体   English

Azure DevOps - 如何执行部署前和部署后 SQL 脚本

[英]Azure DevOps - how to execute Pre and Post Deployment SQL scripts

In Azure DevOps release pipeline, How do I get our Script.PreDeployment.sql and Script.PostDeployment.sql files to execute during our SQL Server database deploy task?在 Azure DevOps 发布管道中,如何让我们的Script.PreDeployment.sqlScript.PostDeployment.sql文件在我们的 SQL Server 数据库部署任务期间执行?

In our release pipeline we have a Database Deployment phase, which has a SQL Server database deploy task.在我们的发布管道中,我们有一个数据库部署阶段,其中有一个 SQL Server 数据库部署任务。 The tasks publishes our DACPAC file just fine.这些任务很好地发布了我们的 DACPAC 文件。 However I cannot figure out how to get the pre and post deployment scripts to execute.但是,我无法弄清楚如何执行部署前和部署后脚本。

Both of the scripts are included in the project, both have the appropriate BuildAction set to PreDeploy and PostDeploy.这两个脚本都包含在项目中,都将适当的 BuildAction 设置为 PreDeploy 和 PostDeploy。 Yet in the logs of the dacpac deployment, there is no indication that the files were run - I have a bunch of PRINT statements in there.然而,在 dacpac 部署的日志中,没有迹象表明文件已运行 - 我在那里有一堆PRINT语句。

I am also working on the post deployment scrip by using SSDT approach, and for deployment I am using the Azure SQL DacpacTask task in my Azure Pipeline, so you just need to create the post deployment scripts as you can see this in image and save it, after you run the Azure build this will add it in the Azure Pipeline artifact ill automatically executed in above azure tasks under release pipeline.我还在使用 SSDT 方法处理部署后脚本,对于部署,我在 Azure Pipeline 中使用Azure SQL DacpacTask任务,因此您只需要创建部署后脚本,如您在图像中看到的那样并保存它, 运行 Azure 构建后,这会将其添加到 Azure Pipeline 工件中,该工件将在发布管道下的上述 azure 任务中自动执行。 First it will executed the database deployment and after that it runs the post deployment script.首先它将执行数据库部署,然后运行部署后脚本。 It works for me .这个对我有用 。

在此处输入图片说明

You can make use of Command line task to run those pre and post deployment SQL script using the SQLCMD tool.您可以使用命令行任务使用SQLCMD工具运行那些部署前和部署后的 SQL 脚本。

The arguments to this its execution script are:它的执行脚本的参数是:

-S {database-server-name}.database.windows.net 

-U {username}@{database-server-name} 

-P {password} 

-d {database-name} 

-i {SQL file}

If you store the pre/postdeployment script in artifact, you can specify -i as like $(System.DefaultWorkingDirectory)/drop/Script.PreDeployment.sql .如果您将部署前/部署后脚本存储在工件中,您可以将 -i 指定为$(System.DefaultWorkingDirectory)/drop/Script.PreDeployment.sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM