我目前有一个管道,可以构建DacPacs并将其部署到我们的本地数据库。然而,我们有一些自托管客户端,他们现在在每个版本上都有一个迁移脚本。我们希望将它们转换为也能够使用DacPacs进行部署。我想知道是否有可能有一个Powershell脚本,从Azure DevOps上的工件目录中拉出DacPac文件?
发布于 2021-03-31 10:27:35
有没有可能有一个Powershell脚本,从Azure DevOps上的工件目录中提取DacPac文件?
在Azure Pipeline中,您需要通过Publish Build Artifacts task发布文件来构建工件。
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop1'
inputs:
PathtoPublish: 'dacpac file path'
ArtifactName: drop然后,您可以使用以下Powershell脚本下载目标文件:
$token = "PAT"
$url1= "https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/build/builds/{BuildId}/artifacts?artifactName={ArtifactsName}&api-version=5.1"
$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
$containerid = $response1.resource.data
echo $containerid
$result= ("$containerid" -split "/")[1]
echo $result
$url="https://dev.azure.com/{OrganizationName}/_apis/resources/Containers/$($result)/{ArtifactsName}?itemPath={path to the item including the root}" #e.g.item file path drop%2FForumContext1.dacpac use %2F replace /
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/octet-stream -OutFile "C:\Response.dacpac"另一方面,Azure Devops还支持直接将Dacpac文件部署到本地数据库。
在发布管道中,可以使用Deployment Group作业中的SQL Server数据库部署任务。

https://stackoverflow.com/questions/66877343
复制相似问题