【问题标题】:Error when deploying DACPAC via Azure DevOps Pipelines通过 Azure DevOps Pipelines 部署 DACPAC 时出错
【发布时间】:2021-01-25 02:14:59
【问题描述】:

我正在使用通过 Azure DevOps Pipelines 部署的 Azure SQL DB 刷新 CI/CD 流程。我正在使用 Adventure 作品数据库并设置了一个导入架构的 Visual Studio 项目。

我有一个配置为发布 dacpac 并使用 SqlAzureDacpacDeployment@1 运行后续部署的管道,并且收到以下错误:

2020-10-10T02:36:34.1421137Z ##[error]Unable to connect to target server 'server.database.windows.net'. Please verify the connection information such as the server name, login credentials, and firewall rules for the target server.
2020-10-10T02:36:34.1605855Z ##[error]Windows logins are not supported in this version of SQL Server.
2020-10-10T02:36:34.2143924Z ##[error]The Azure SQL DACPAC task failed. SqlPackage.exe exited with code 1.Check out how to troubleshoot failures at https://aka.ms/sqlazuredeployreadme#troubleshooting-
2020-10-10T02:36:34.2522414Z ##[section]Finishing: SqlAzureDacpacDeployment

我正在使用最新的 Windows,这是我的 YAML 管道:

trigger:
- master

pool:
  vmImage: 'windows-latest'


jobs: 
- job: BuildDeploySQL
  variables:
  - group: SQLServerLogin
  steps:
  - task: VSBuild@1
    inputs:
      solution: '**\*.sln'
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Pipeline.Workspace)'
      publishLocation: 'pipeline'
  - task: SqlAzureDacpacDeployment@1
    inputs:
      azureSubscription: 'Subscription Name here'
      AuthenticationType: 'server'
      ServerName: 'server.database.windows.net'
      DatabaseName: 'AdventureWorks'
      SqlUsername: 'sqladmin'
      SqlPassword: ${{ variables.Password }}
      deployType: 'DacpacTask'
      DeploymentAction: 'Publish'
      DacpacFile: '$(Pipeline.Workspace)\s\AdventureWorks\bin\Debug\*.dacpac'
      IpDetectionMethod: 'AutoDetect'

我尝试从我的本地计算机进行部署,并且使用相同的 sql 凭据成功。此外,我已确认 SQL 数据库已启用 Azure 服务。我还尝试将 dacpac 部署到一个新的空数据库并得到同样的错误。

我确实认为这可能只是一般错误消息,因为我的部署日志确实显示成功连接到服务器:

2020-10-10T02:36:18.7912964Z Invoke-Sqlcmd -ServerInstance "server.database.windows.net" -Database "AdventureWorks" -Username "sqladmin"  -Password ******  -Inputfile 
....
2020-10-10T02:36:33.0554895Z Initializing deployment (Start)

** 更新 只是为了排除我确实创建了一个具有 DBO_owner 权限的新 SQL 登录并使用它运行部署并得到了相同的错误消息。

【问题讨论】:

    标签: azure azure-devops azure-sql-database azure-pipelines dac


    【解决方案1】:

    上述错误可能是因为构建代理 ip 未在 Azure SQL 数据库的防火墙规则中列出。请参阅有关IP ranges for Microsoft-hosted agents 的此链接。

    您可以检查您的天蓝色数据库的防火墙规则设置,并尝试允许所有 IP 范围。

    您还可以添加 Azure CLi 任务以获取代理 ip 并为您的 azure 数据库设置防火墙规则以允许代理 ip 在您的管道中动态地使用。见this thread

    steps:
    - task: AzureCLI@2
      displayName: 'Azure CLI '
      inputs:
        azureSubscription: 'azureSubscription'
        scriptType: ps
        scriptLocation: inlineScript
        inlineScript: |
         
         $agentIp = (New-Object net.webclient).downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"
         
         az sql server firewall-rule create -g $(rg) -s $(server) -n test --start-ip-address $agentIp --end-ip-address $agentIp
    

    您还可以在本地计算机/Azure VM 上创建self-hosted agent。并在此自托管代理上运行您的管道。请注意将您的本地计算机 IP 列入 azure 数据库的许可名单。

    【讨论】:

    • 这是很棒的信息!我确实将上述任务添加到我的 ADO 管道中。该任务确实有效并更新了防火墙设置;但是,我仍然收到与上述相同的错误消息。这些任务没有并行运行,因此部署步骤应该在同一个代理上。
    • @DreadedFrost 您是否尝试过使用连接字符串作为身份验证类型?
    • 问题是 secreate 密码中的特殊字符。用引号括起来就解决了。
    【解决方案2】:

    根本问题是密码机密包含逃脱 Powershell 的字符。将秘密包装在 "" 中解决了它。

    【讨论】:

    • 你能详细说明一下吗?现在粘贴管道中的实际参数?引号到底在哪里?我得到语法错误
    猜你喜欢
    • 2020-09-06
    • 1970-01-01
    • 2020-09-23
    • 2021-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 2021-08-21
    相关资源
    最近更新 更多