通过发布管理部署dacpac时可以使用DeployReport选项吗 [英] Can I use the DeployReport option when deploying a dacpac through Release Management

查看:76
本文介绍了通过发布管理部署dacpac时可以使用DeployReport选项吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to be able to setup a WinRM dacpac deployment task in MS Release Management to create a report of the schema compare and not actually deploy the database. Then I could have an environment approval and abandon the deployment if unexpected changes are reported. If the changes are as expected, the next environment would actually deploy the database.

有没有一种方法可以使用可用的WinRM DB部署任务?如果可以,怎么办?

Is there a way to do that using the available WinRM DB deployment task? If so, how?

推荐答案

发布"在任务脚本中进行了硬编码,因此我们最终创建了一个执行此操作的Powershell脚本.通常修改任务中的相关代码( https://github.com/Microsoft/vsts-tasks/tree/master/Tasks/SqlDacpacDeploymentOnMachineGroup ),并导入任务使用的实用程序文件(

'Publish' is hardcoded in the task script, so we wound up creating a powershell script that does this. Mostly modified the relevant code from the task (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). Then just changed the hardcoded value and added the output file parameter. Then we read in the report file and display it in the release log for the powershell task. abest's comment is a good idea, but it looks like we don't currently have that task available at our site.

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

这篇关于通过发布管理部署dacpac时可以使用DeployReport选项吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆