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

Noo*_*aet 2 azure azure-sql-database azure-devops azure-pipelines azure-pipelines-release-pipeline

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

这种情况下的解决办法是什么?

Mac*_*ser 7

在连接数据库之前,您可以根据代理的当前 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
Run Code Online (Sandbox Code Playgroud)

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

  • @NoorAllSafaet您可以将 Azure SQL 数据库部署任务的“IpDetectionMethod(指定防火墙规则使用)”字段设置为“AutoDetect”,这将自动将代理 IP 添加到防火墙规则中。 (2认同)