小编Ada*_*ort的帖子

如何通过 Azure DevOps 发布管道中的 Azure Powershell 更新暂存槽的 IP 白名单?

我有一个托管在 Azure 中的应用程序,我使用 Azure DevOps 来管理我的构建和发布管道。作为发布的一部分,我通过向根 url 发出请求来预热应用程序(例如https://myapp.azurewebsites.net)。为了发出此请求,我必须首先确保运行部署的托管构建代理可以访问该 url(否则我将收到 403)。我编写了一个简短的 powershell 脚本来实现这一点,并将其放入 Azure Powershell 任务中。它将构建代理的 IP 添加到应用服务的 IpSecurityConfiguration。到现在为止还挺好。它非常适合只是应用程序的应用程序。它失败的地方是当我尝试在登台环境中使用它时。当我们发布到生产环境时,我们首先将代码推送到暂存槽,然后在我们运行测试并确保一切正常后将其翻转过来。正确处理应用服务的 IpSecurityConfiguration 的 powershell 脚本在暂存槽上不起作用。要访问暂存槽,我们对变量 $(WebApiName) 使用 myappname/slots/staging,通常它只是应用程序服务本身的名称。同样,如果我从本地环境运行脚本,这将非常有效,它只会在管道中失败。代码如下:

# Whitelist Azure Agent IPs

$agentIP = Invoke-RestMethod http://ipinfo.io/json | Select -exp ip

Write-Host "Connecting to Azure"

$APIVersion = ((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Web).ResourceTypes | Where-Object ResourceTypeName -eq sites).ApiVersions[0]
Write-Host "API Version is $APIVersion. Getting web app config for $(WebApiName) in $(ResourceGroupName)"

$WebApiConfig = (Get-AzureRmResource -ResourceType Microsoft.Web/sites/config -ResourceName $(WebApiName) -ResourceGroupName $(ResourceGroupName) -ApiVersion $APIVersion)


Write-Host "Got …
Run Code Online (Sandbox Code Playgroud)

powershell azure-web-app-service azure-devops azure-pipelines

3
推荐指数
1
解决办法
679
查看次数