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

Add application insights connection string support - APPLICATIONINSIGHTS_CONNECTION_STRING #19855

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AzureEndpoint } from 'azure-pipelines-tasks-azure-arm-rest/azureModels'
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 @@ -89,4 +89,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;
}
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppContainerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppContainerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
FinVamp1 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -91,3 +91,20 @@ function getPipelineVariable(variableName: string): string | undefined {
//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;
}
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"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 @@ -91,3 +91,20 @@ function getPipelineVariable(variableName: string): string | undefined {
//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;
}
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"releaseNotes": "What's new in version 2.* <br /> Removed WAR Deploy Support, setting Web.Config options, and the option for the Startup command for Linux Azure Function Apps.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
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 @@ -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;
}
8 changes: 4 additions & 4 deletions Tasks/AzureRmWebAppDeploymentV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"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 Expand Up @@ -622,12 +622,12 @@
],
"instanceNameFormat": "Azure App Service Deploy: $(WebAppName)",
"execution": {
"Node10": {
"target": "azurermwebappdeployment.js"
},
"Node16": {
"target": "azurermwebappdeployment.js",
"argumentFormat": ""
},
"Node10": {
"target": "azurermwebappdeployment.js"
}
},
"messages": {
Expand Down
8 changes: 4 additions & 4 deletions Tasks/AzureRmWebAppDeploymentV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down Expand Up @@ -622,12 +622,12 @@
],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
"execution": {
"Node10": {
"target": "azurermwebappdeployment.js"
},
"Node16": {
"target": "azurermwebappdeployment.js",
"argumentFormat": ""
},
"Node10": {
"target": "azurermwebappdeployment.js"
}
},
"messages": {
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 @@ -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;
}
8 changes: 4 additions & 4 deletions Tasks/AzureRmWebAppDeploymentV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"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 Expand Up @@ -495,12 +495,12 @@
],
"instanceNameFormat": "Azure App Service Deploy: $(WebAppName)",
"execution": {
"Node10": {
"target": "azurermwebappdeployment.js"
},
"Node16": {
"target": "azurermwebappdeployment.js",
"argumentFormat": ""
},
"Node10": {
"target": "azurermwebappdeployment.js"
}
},
"messages": {
Expand Down
8 changes: 4 additions & 4 deletions Tasks/AzureRmWebAppDeploymentV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down Expand Up @@ -495,12 +495,12 @@
],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
"execution": {
"Node10": {
"target": "azurermwebappdeployment.js"
},
"Node16": {
"target": "azurermwebappdeployment.js",
"argumentFormat": ""
},
"Node10": {
"target": "azurermwebappdeployment.js"
}
},
"messages": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AzureEndpoint } from 'azure-pipelines-tasks-azure-arm-rest/azureModels'
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 @@ -89,4 +89,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;
}
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppContainerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebAppContainerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 238,
"Minor": 240,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
21 changes: 19 additions & 2 deletions Tasks/AzureWebAppV1/operations/ReleaseAnnotationUtility.ts
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 @@ -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;
}
Loading