通过发行管理部署DACPAC时,我可以使用DeployReport选项吗?



我希望能够在MS Release Management中设置WINRM DACPAC部署任务,以创建架构比较的报告,而不是实际部署数据库。然后,如果报告了意外的更改,我可以获得环境批准,并放弃部署。如果更改如预期,下一个环境实际上将部署数据库。

有没有办法使用可用的WINRM DB部署任务来做到这一点?如果是这样,如何?

'发布'是在任务脚本中进行了硬编码的,因此我们最终创建了一个可以执行此操作的PowerShell脚本。大多从任务(https://github.com/microsoft/vsts/vsts/tree/master/master/master/tasks/sqldacpacdeploymentonmachinegroup)中修改了相关代码,并导入了任务(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 "$PSScriptRootSqlPackageOnTargetMachines.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

相关内容

最新更新