为什么会在我的发布管道中自动创建发布注释?

时间:2021-04-22 17:01:25

标签: azure azure-devops azure-web-app-service azure-application-insights

我注意到,当我们执行发布管道时,现在为几个 Application Insights 实例添加了 release annotations。我们没有做文章中提到的任何事情。这些注释来自哪里?

它似乎只发生在我们的应用程序发布管道上,而不是基础设施上。我们的大多数应用程序都在应用服务上运行,但并非所有应用程序都有发布注释。

1 个答案:

答案 0 :(得分:1)

Azure App Service Deploy Task 会自动创建发布注释。

唯一的先决条件是应用服务在其 AppSettings 中具有有效的 APPINSIGHTS_INSTRUMENTATIONKEY

AppService Deploy Logs

这是相关的代码块:

https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/Common/AzureRmDeploy-common/operations/ReleaseAnnotationUtility.ts

export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
    try {
        var appSettings = await azureAppService.getApplicationSettings();
        var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
        if(instrumentationKey) {
            let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
            var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
            if(appInsightsResources.length > 0) {
                var appInsights: AzureApplicationInsights = new AzureApplicationInsights(endpoint, appInsightsResources[0].id.split('/')[4], appInsightsResources[0].name);
                var releaseAnnotationData = getReleaseAnnotation(isDeploymentSuccess);
                await appInsights.addReleaseAnnotation(releaseAnnotationData);
                console.log(tl.loc("SuccessfullyAddedReleaseAnnotation", appInsightsResources[0].name));
            }