The Azure App Service Deploy Task automatically creates release annotations.
The only prerequisite is that the App Service has a valid APPINSIGHTS_INSTRUMENTATIONKEY
in its AppSettings.
This is the relevant code block:
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));
}