Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support application insights connection string for web apps #20844

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import tl = require('azure-pipelines-task-lib/task');
import { AzureAppService } from 'azure-pipelines-tasks-azure-arm-rest/azure-arm-app-service';
import { AzureApplicationInsights, ApplicationInsightsResources} from 'azure-pipelines-tasks-azure-arm-rest/azure-arm-appinsights';
import { AzureApplicationInsights, ApplicationInsightsResources } from 'azure-pipelines-tasks-azure-arm-rest/azure-arm-appinsights';
import { AzureEndpoint } from 'azure-pipelines-tasks-azure-arm-rest/azureModels';

var uuidV4 = require("uuid/v4");

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;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand All @@ -31,7 +31,7 @@ export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppServ
}
}

function getReleaseAnnotation(isDeploymentSuccess: boolean): {[key: string]: any} {
function getReleaseAnnotation(isDeploymentSuccess: boolean): { [key: string]: any } {
let annotationName = "Release Annotation";
let releaseUri = tl.getVariable("Release.ReleaseUri");
let buildUri = tl.getVariable("Build.BuildUri");
Expand All @@ -42,7 +42,7 @@ function getReleaseAnnotation(isDeploymentSuccess: boolean): {[key: string]: any
else if (!!buildUri) {
annotationName = `${tl.getVariable("Build.DefinitionName")} - ${tl.getVariable("Build.BuildNumber")}`;
}

let releaseAnnotationProperties = {
"Label": isDeploymentSuccess ? "Success" : "Error", // Label decides the icon for release annotation
"Deployment Uri": getDeploymentUri(),
Expand Down Expand Up @@ -90,4 +90,21 @@ function getPipelineVariable(variableName: string): string | undefined {
let variable = tl.getVariable(variableName);
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString) {
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
4 changes: 2 additions & 2 deletions Tasks/AzureRmWebAppDeploymentV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 247,
"Patch": 1
"Minor": 253,
"Patch": 0
},
"releaseNotes": "What's new in Version 3.0: <br/>&nbsp;&nbsp;Supports File Transformations (XDT) <br/>&nbsp;&nbsp;Supports Variable Substitutions(XML, JSON) <br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more information.",
"minimumAgentVersion": "2.104.1",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureRmWebAppDeploymentV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 247,
"Patch": 1
"Minor": 253,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var uuidV4 = require("uuid/v4");
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;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -42,7 +42,7 @@ function getReleaseAnnotation(isDeploymentSuccess: boolean): {[key: string]: any
else if (!!buildUri) {
annotationName = `${tl.getVariable("Build.DefinitionName")} - ${tl.getVariable("Build.BuildNumber")}`;
}

let releaseAnnotationProperties = {
"Label": isDeploymentSuccess ? "Success" : "Error", // Label decides the icon for release annotation
"Deployment Uri": getDeploymentUri(),
Expand Down Expand Up @@ -90,4 +90,21 @@ function getPipelineVariable(variableName: string): string | undefined {
let variable = tl.getVariable(variableName);
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString) {
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
4 changes: 2 additions & 2 deletions Tasks/AzureRmWebAppDeploymentV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 4,
"Minor": 247,
"Patch": 1
"Minor": 253,
"Patch": 0
},
"releaseNotes": "What's new in version 4.*<br />Supports Zip Deploy, Run From Package, War Deploy [Details here](https://aka.ms/appServiceDeploymentMethods)<br />Supports App Service Environments<br />Improved UI for discovering different App service types supported by the task<br/>Run From Package is the preferred deployment method, which makes files in wwwroot folder read-only<br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more information.",
"minimumAgentVersion": "2.104.1",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureRmWebAppDeploymentV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 4,
"Minor": 247,
"Patch": 1
"Minor": 253,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down