Azure:创建部署时找不到资源(应用洞察)

问题描述 投票:0回答:1

[在TeamCity中运行构建时,我们运行一些Azure脚本。但是偶尔我会收到关于找不到资源的错误(应用程序见解)。错误是:

ERROR: Deployment failed. Correlation ID: ############. {
"Code": "BadRequest",
"Message": "Unable to find the resource /subscriptions/###########/resourceGroups/myResourceGroup/providers/microsoft.insights/components/myAppInsight, please confirm that it exists."

}

我们使用的脚本是:

az extension add -n application-insights
az monitor app-insights component create --app $functionAppName --location $location --resource-group $rgTelemetryConfig --tags $tags

az functionapp create -n $functionAppName -g $rgTelemetryConfig --app-insights $functionAppName --storage-account $storageAccount --consumption-plan-location $location --tags $tags --runtime $runtime
az group deployment create --resource-group $rgTelemetryConfig --template-file ./templates/monitoring/config-template.json --parameters appInsights=$functionAppName

在arm模板中,我们确实多次引用了appInsights,例如:

"actionGroupId": "[resourceId('microsoft.insights/actionGroups', parameters('actionGroup'))]"
"scopes": [
                "[resourceId('microsoft.insights/components', parameters('appInsights'))]"
            ]
"componentId": "[resourceId('microsoft.insights/components', parameters('appInsights'))]"

有人知道我应该如何解决吗?

azure teamcity azure-cli
1个回答
0
投票

您的脚本看起来不错,如果您偶尔遇到错误,我想有时在完全创建应用程序见解之前就已经使用过。

要解决该问题,您可以尝试在sleep 10之后添加az monitor app-insights component create

az extension add -n application-insights
az monitor app-insights component create --app $functionAppName --location $location --resource-group $rgTelemetryConfig --tags $tags
sleep 10

az functionapp create -n $functionAppName -g $rgTelemetryConfig --app-insights $functionAppName --storage-account $storageAccount --consumption-plan-location $location --tags $tags --runtime $runtime
az group deployment create --resource-group $rgTelemetryConfig --template-file ./templates/monitoring/config-template.json --parameters appInsights=$functionAppName
© www.soinside.com 2019 - 2024. All rights reserved.