【问题标题】:Azure DevOps/Pipeline IP is changing randomly so I can not use Azure SQL Database because of firewall rulesAzure DevOps/Pipeline IP 随机更改,因此由于防火墙规则,我无法使用 Azure SQL 数据库
【发布时间】:2020-10-09 15:12:57
【问题描述】:

Azure DevOps/Pipeline IP 随机更改,因此由于防火墙规则,我无法使用 Azure SQL 数据库。

这种情况有什么解决办法?

【问题讨论】:

    标签: azure azure-devops azure-sql-database azure-pipelines azure-pipelines-release-pipeline


    【解决方案1】:

    您可以在连接数据库之前根据代理的当前 ip 创建防火墙规则,如下所示:

      - task: AzureCLI@2
        inputs:
          azureSubscription: [name of service connection]
          scriptType: pscore
          scriptLocation: inlineScript
          inlineScript: |
            # Set firewall on server open for the agent
            $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
    

    以类似的方式,您可以在管道末端将其移除。

    【讨论】:

    • 您知道使用模板而不是命令的解决方案吗?您正在展示正确的方式,但我需要使用模板来做同样的事情。
    • 这个变化是你的意思吗?
    • 我说的是我们从任务列表中选择的模板。
    • 您指的是经典管道吗?我的回答适用于 yaml 管道。
    • @NoorAllSafaet 您可以将 Azure SQL 数据库部署任务的 IpDetectionMethod(Specify Firewall Rules Using) 字段设置为 AutoDetect,这会自动将代理 ip 添加到防火墙规则中。
    【解决方案2】:

    我在 Azure SQL 数据库防火墙中添加了 Azure IP 范围,然后它就可以工作了。 例如:

    Start IP 13.107.6.0 and End IP 13.107.6.255
    

    Start IP 13.107.43.0 and End IP 13.107.43.255
    

    我不确定这是一个永久的解决方案。

    微软文档参考Allowed address lists and network connections

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多