首页 > 解决方案 > 如何将 Azure DevOps 构建管道连接到专用终结点

问题描述

我正在尝试通过 Azure DevOps 构建管道对托管在 Azure App Service 中的 node.js 应用程序执行 mocha 测试。下面是我正在使用的发布管道代码

    # Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- Test

pool:
  vmImage: 'vs2017-win2016'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.14.1'
  displayName: 'Install Node.js'

- script: |
    npm install
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'npm run local

- task: PublishTestResults@2
  condition: succeededOrFailed()
  inputs:
    testRunner: JUnit
    testResultsFiles: 'test-results.xml'

- task: ArchiveFiles@2
  displayName: 'Archive $(System.DefaultWorkingDirectory)'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
    archiveFile: '$(Build.ArtifactStagingDirectory)/node.zip'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

当我运行构建时,我收到以下错误

{"name":"xxxx","hostname":"xxxx","pid":xxxx,"level":50,"msg":"Error while connecting sql database xxxx-dev","time":"2020-11-17T11:37:26.852Z","v":0} 
[0] {"name":"xxxxx","hostname":"xxxxxx","pid":xxxx,"level":50,"err":{"message":"Reason: An instance-specific error occurred while establishing a connection to SQL Server. Connection was denied since Deny Public Network Access is set to Yes (https://docs.microsoft.com/azure/azure-sql/database/connectivity-settings#deny-public-network-access). To connect to this server, use the Private Endpoint from inside your virtual network (https://docs.microsoft.com/azure/sql-database/sql-database-private-endpoint-overview#how-to-set-up-private-link-for-azure-sql-database).","name":"ConnectionError","stack":"ConnectionError: Reason: An instance-specific error occurred while establishing a connection to SQL Server. Connection was denied since Deny Public Network Access is set to Yes (
[0] {"name":"xxxx-device-controller","hostname":"xxxxx","pid":xxxx,"level":50,"msg":"Error while attempting to complete call","time":"2020-11-17T11:37:26.852Z","v":0} 

有没有办法直接在 App 服务中运行测试?或者如何建立连接

标签: node.jsazureazure-devopsazure-web-app-servicemocha.js

解决方案


为了连接到 SQL 数据库,ip 应该被列入白名单(Set server firewallOverview数据库的选项卡中。因此,您需要构建服务器的 ip 地址。由于此 ip 可以随着每次构建而更改,因此需要从内部添加管道。_

如何做到这一点已在本文中讨论。您将需要稍微修改命令:

  • 将 ip 列入白名单:New-AzureRmSqlServerFirewallRule而不是Add-AzWebAppAccessRestrictionRule. 您应该能够获得所有必需的参数,请参阅文档
  • ip地址将从管道中删除Remove-AzureRmSqlServerFirewallRule

推荐阅读