通过 Release Management 部署 dacpac 时,我可以使用 DeployReport 选项吗
Can I use the DeployReport option when deploying a dacpac through Release Management
我希望能够在 MS Release Management 中设置 WinRM dacpac 部署任务以创建模式比较报告,而不是实际部署数据库。然后我可以获得环境批准并在报告意外更改时放弃部署。如果变化符合预期,下一个环境就会真正部署数据库。
有没有办法使用可用的 WinRM 数据库部署任务来做到这一点?如果是,怎么做?
'Publish' 在任务脚本中被硬编码,因此我们最终创建了一个执行此操作的 powershell 脚本。主要修改了任务中的相关代码(https://github.com/Microsoft/vsts-tasks/tree/master/Tasks/SqlDacpacDeploymentOnMachineGroup) and imported the utility file used by the task (https://github.com/Microsoft/vsts-rm-extensions/blob/master/TaskModules/powershell/TaskModuleSqlUtility/SqlPackageOnTargetMachines.ps1)。然后只需更改硬编码值并添加输出文件参数。然后我们读入报告文件并将其显示在 powershell 任务的发布日志中。 abest 的评论是个好主意,但看起来我们目前在我们的站点上没有可用的任务。
param (
[string]$dacpacFile = $(throw "dacpacFile is mandatory, please provide a value."),
[string]$publishProfile = $(throw "publishProfile is mandatory, please provide a value."),
[string]$targetDBServer = $(throw "targetDBServer is mandatory, please provide a value."),
[string]$targetDBName = $(throw "targetDBName is mandatory, please provide a value."),
[string]$outputPath = $(throw "outputPath is mandatory, please provide a value.")
)
Import-Module "$PSScriptRoot\SqlPackageOnTargetMachines.ps1"
function Get-SqlPackageCmdArgsDeployReport
{
param (
[string]$dacpacPath,
[string]$publishProfile,
[string]$server,
[string]$dbName
)
try
{
# validate dacpac file
if ([System.IO.Path]::GetExtension($dacpacPath) -ne ".dacpac")
{
throw "Invalid Dacpac file [ $dacpacPath ] provided"
}
}
catch [System.Exception]
{
Write-Verbose ("Could not verify DacPac : " + $_.Exception.Message) -Verbose
}
$sqlPkgCmdArgs = [string]::Format(' /SourceFile:"{0}" /Action:DeployReport', $dacpacPath)
try
{
# validate output file
if ([System.IO.Path]::GetExtension($outputPath) -ne ".xml")
{
throw "Invalid output file [ $outputPath ] provided, that should be an xml file really"
}
$sqlPkgCmdArgs = [string]::Format('{0} /OutputPath:"{1}"', $sqlPkgCmdArgs, $outputPath)
}
catch [System.Exception]
{
Write-Verbose ("Could not verify ouput path : " + $_.Exception.Message) -Verbose
}
if( ![string]::IsNullOrWhiteSpace($publishProfile) )
{
try
{
# validate publish profile
if ([System.IO.Path]::GetExtension($publishProfile) -ne ".xml")
{
throw "Invalid Publish Profile [ $publishProfile ] provided"
}
$sqlPkgCmdArgs = [string]::Format('{0} /Profile:"{1}"', $sqlPkgCmdArgs, $publishProfile)
}
catch [System.Exception]
{
Write-Verbose ("Could not verify profile : " + $_.Exception.Message) -Verbose
}
}
if( ![string]::IsNullOrWhiteSpace($dbName) )
{
$sqlPkgCmdArgs = [string]::Format('{0} /TargetServerName:"{1}" /TargetDatabaseName:"{2}"', $sqlPkgCmdArgs, $server, $dbName)
}
#Write-Verbose "Sqlpackage.exe arguments : $sqlPkgCmdArgs" -Verbose
return $sqlPkgCmdArgs
}
function Format-XML ([xml]$xml, $indent=2)
{
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
$xmlWriter.Formatting = “indented”
$xmlWriter.Indentation = $Indent
$xml.WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
Write-Output $StringWriter.ToString()
}
$sqlPackage = Get-SqlPackageOnTargetMachine
#Write-Verbose "So the path the SQL Package is $sqlPackage ?" -Verbose
$sqlPackageArguments = Get-SqlPackageCmdArgsDeployReport $dacPacFile $publishProfile $targetDBServer $targetDBName
Write-Verbose("Running ExecuteCommand -FileName ""$sqlPackage"" -Arguments $sqlPackageArguments") -Verbose
ExecuteCommand -FileName "$sqlPackage" -Arguments $sqlPackageArguments
[xml]$report = Get-Content $outputPath
Format-XML $report -indent 4 | Write-Verbose -Verbose
我希望能够在 MS Release Management 中设置 WinRM dacpac 部署任务以创建模式比较报告,而不是实际部署数据库。然后我可以获得环境批准并在报告意外更改时放弃部署。如果变化符合预期,下一个环境就会真正部署数据库。
有没有办法使用可用的 WinRM 数据库部署任务来做到这一点?如果是,怎么做?
'Publish' 在任务脚本中被硬编码,因此我们最终创建了一个执行此操作的 powershell 脚本。主要修改了任务中的相关代码(https://github.com/Microsoft/vsts-tasks/tree/master/Tasks/SqlDacpacDeploymentOnMachineGroup) and imported the utility file used by the task (https://github.com/Microsoft/vsts-rm-extensions/blob/master/TaskModules/powershell/TaskModuleSqlUtility/SqlPackageOnTargetMachines.ps1)。然后只需更改硬编码值并添加输出文件参数。然后我们读入报告文件并将其显示在 powershell 任务的发布日志中。 abest 的评论是个好主意,但看起来我们目前在我们的站点上没有可用的任务。
param (
[string]$dacpacFile = $(throw "dacpacFile is mandatory, please provide a value."),
[string]$publishProfile = $(throw "publishProfile is mandatory, please provide a value."),
[string]$targetDBServer = $(throw "targetDBServer is mandatory, please provide a value."),
[string]$targetDBName = $(throw "targetDBName is mandatory, please provide a value."),
[string]$outputPath = $(throw "outputPath is mandatory, please provide a value.")
)
Import-Module "$PSScriptRoot\SqlPackageOnTargetMachines.ps1"
function Get-SqlPackageCmdArgsDeployReport
{
param (
[string]$dacpacPath,
[string]$publishProfile,
[string]$server,
[string]$dbName
)
try
{
# validate dacpac file
if ([System.IO.Path]::GetExtension($dacpacPath) -ne ".dacpac")
{
throw "Invalid Dacpac file [ $dacpacPath ] provided"
}
}
catch [System.Exception]
{
Write-Verbose ("Could not verify DacPac : " + $_.Exception.Message) -Verbose
}
$sqlPkgCmdArgs = [string]::Format(' /SourceFile:"{0}" /Action:DeployReport', $dacpacPath)
try
{
# validate output file
if ([System.IO.Path]::GetExtension($outputPath) -ne ".xml")
{
throw "Invalid output file [ $outputPath ] provided, that should be an xml file really"
}
$sqlPkgCmdArgs = [string]::Format('{0} /OutputPath:"{1}"', $sqlPkgCmdArgs, $outputPath)
}
catch [System.Exception]
{
Write-Verbose ("Could not verify ouput path : " + $_.Exception.Message) -Verbose
}
if( ![string]::IsNullOrWhiteSpace($publishProfile) )
{
try
{
# validate publish profile
if ([System.IO.Path]::GetExtension($publishProfile) -ne ".xml")
{
throw "Invalid Publish Profile [ $publishProfile ] provided"
}
$sqlPkgCmdArgs = [string]::Format('{0} /Profile:"{1}"', $sqlPkgCmdArgs, $publishProfile)
}
catch [System.Exception]
{
Write-Verbose ("Could not verify profile : " + $_.Exception.Message) -Verbose
}
}
if( ![string]::IsNullOrWhiteSpace($dbName) )
{
$sqlPkgCmdArgs = [string]::Format('{0} /TargetServerName:"{1}" /TargetDatabaseName:"{2}"', $sqlPkgCmdArgs, $server, $dbName)
}
#Write-Verbose "Sqlpackage.exe arguments : $sqlPkgCmdArgs" -Verbose
return $sqlPkgCmdArgs
}
function Format-XML ([xml]$xml, $indent=2)
{
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
$xmlWriter.Formatting = “indented”
$xmlWriter.Indentation = $Indent
$xml.WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
Write-Output $StringWriter.ToString()
}
$sqlPackage = Get-SqlPackageOnTargetMachine
#Write-Verbose "So the path the SQL Package is $sqlPackage ?" -Verbose
$sqlPackageArguments = Get-SqlPackageCmdArgsDeployReport $dacPacFile $publishProfile $targetDBServer $targetDBName
Write-Verbose("Running ExecuteCommand -FileName ""$sqlPackage"" -Arguments $sqlPackageArguments") -Verbose
ExecuteCommand -FileName "$sqlPackage" -Arguments $sqlPackageArguments
[xml]$report = Get-Content $outputPath
Format-XML $report -indent 4 | Write-Verbose -Verbose