Skip to content

Commit 7779763

Browse files
Port to M161: AzureResourceGroupDeploymentTask: Improving error log to point to Deployment logs in Ibiza Portal (#11853) (#11904)
* AzureResourceGroupDeploymentTask: Improving error log to point to Deployment logs in Ibiza Portal (#11853) * Init * Refactoring * Update Tasks/AzureResourceManagerTemplateDeploymentV3/task.json Co-Authored-By: Bishal Prasad <[email protected]> * Adding functionality for AzureResourceGroupDeploymentV2 * Updating error message * Handling deploymentScope as Resource Group * Handling management group * Updating message * Review comments * Updating task version * Bug fix * Print log for subscription as well * Bug fix * Adding check for Subscription * Bug fix * Bug fix * 500 errors are shown * Bug fix * Bug fix
1 parent cc91a0a commit 7779763

File tree

8 files changed

+62
-10
lines changed

8 files changed

+62
-10
lines changed

Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,6 @@
191191
"loc.messages.LogDeploymentName": "Deployment name is %s",
192192
"loc.messages.ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.",
193193
"loc.messages.DeploymentGroupConfigurationNotSucceeded": "Deployment group configuration did not succeed on one or more Virtual Machine(s): %s",
194-
"loc.messages.DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s"
194+
"loc.messages.DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s",
195+
"loc.messages.FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s"
195196
}

Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ export class ResourceGroup {
514514
}
515515
if (result.error) {
516516
this.writeDeploymentErrors(result.error);
517+
tl.error(tl.loc("FindMoreDeploymentDetailsAzurePortal", this.getAzurePortalDeploymentURL()));
517518
return reject(tl.loc("CreateTemplateDeploymentFailed"));
518519
} else {
519520
console.log(tl.loc("ValidDeployment"));
@@ -537,6 +538,7 @@ export class ResourceGroup {
537538
return this.waitAndPerformAzureDeployment(armClient, deployment, retryCount);
538539
}
539540
this.writeDeploymentErrors(error);
541+
this.checkAndPrintPortalDeploymentURL(error);
540542
return reject(tl.loc("CreateTemplateDeploymentFailed"));
541543
}
542544
if (result && result["properties"] && result["properties"]["outputs"] && utils.isNonEmpty(this.taskParameters.deploymentOutputs)) {
@@ -551,6 +553,12 @@ export class ResourceGroup {
551553
}
552554
}
553555

556+
protected checkAndPrintPortalDeploymentURL(error: any) {
557+
if(!!error && (error.statusCode < 400 || error.statusCode >= 500)) {
558+
tl.error(tl.loc("FindMoreDeploymentDetailsAzurePortal", this.getAzurePortalDeploymentURL()));
559+
}
560+
}
561+
554562
private async waitAndPerformAzureDeployment(armClient: armResource.ResourceManagementClient, deployment: Deployment, retryCount): Promise<void> {
555563
await sleepFor(3);
556564
return this.performAzureDeployment(armClient, deployment, retryCount - 1);
@@ -569,6 +577,18 @@ export class ResourceGroup {
569577
await this.performAzureDeployment(armClient, deployment, 3);
570578
}
571579

580+
private getAzurePortalDeploymentURL() {
581+
try {
582+
let portalUrl = this.taskParameters.endpointPortalUrl ? this.taskParameters.endpointPortalUrl : "https://portal.azure.com";
583+
portalUrl += "/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/";
584+
let subscriptionSpecificURL = "/subscriptions/" + this.taskParameters.subscriptionId + "/resourceGroups/" + this.taskParameters.resourceGroupName + "/providers/Microsoft.Resources/deployments/" + this.taskParameters.deploymentName;
585+
return portalUrl + subscriptionSpecificURL.replace(/\//g, '%2F');
586+
} catch (error) {
587+
tl.error(error);
588+
return error;
589+
}
590+
}
591+
572592
private escapeBlockCharacters(str: string): string {
573593
return str.replace(/[\[]/g, '$&[]');
574594
}

Tasks/AzureResourceGroupDeploymentV2/task.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 2,
1717
"Minor": 157,
18-
"Patch": 7
18+
"Patch": 8
1919
},
2020
"demands": [],
2121
"minimumAgentVersion": "2.119.1",
@@ -480,6 +480,7 @@
480480
"LogDeploymentName": "Deployment name is %s",
481481
"ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.",
482482
"DeploymentGroupConfigurationNotSucceeded": "Deployment group configuration did not succeed on one or more Virtual Machine(s): %s",
483-
"DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s"
483+
"DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s",
484+
"FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s"
484485
}
485486
}

Tasks/AzureResourceGroupDeploymentV2/task.loc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 2,
1717
"Minor": 157,
18-
"Patch": 7
18+
"Patch": 8
1919
},
2020
"demands": [],
2121
"minimumAgentVersion": "2.119.1",
@@ -480,6 +480,7 @@
480480
"LogDeploymentName": "ms-resource:loc.messages.LogDeploymentName",
481481
"ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal",
482482
"DeploymentGroupConfigurationNotSucceeded": "ms-resource:loc.messages.DeploymentGroupConfigurationNotSucceeded",
483-
"DeploymentGroupConfigurationFailedOnVM": "ms-resource:loc.messages.DeploymentGroupConfigurationFailedOnVM"
483+
"DeploymentGroupConfigurationFailedOnVM": "ms-resource:loc.messages.DeploymentGroupConfigurationFailedOnVM",
484+
"FindMoreDeploymentDetailsAzurePortal": "ms-resource:loc.messages.FindMoreDeploymentDetailsAzurePortal"
484485
}
485486
}

Tasks/AzureResourceManagerTemplateDeploymentV3/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@
8282
"loc.messages.ResourceGroupNameNotProvided": "Resource Group name should be provided",
8383
"loc.messages.LocationNotProvided": "Location is required for deployment",
8484
"loc.messages.ARMServiceConnectionScope": "ARM Service Conection deployment scope - %s",
85-
"loc.messages.CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope"
85+
"loc.messages.CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope",
86+
"loc.messages.FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s"
8687
}

Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class DeploymentScopeBase {
5454
return this.waitAndPerformAzureDeployment(retryCount);
5555
}
5656
utils.writeDeploymentErrors(this.taskParameters, error);
57+
this.checkAndPrintPortalDeploymentURL(error);
5758
return reject(tl.loc("CreateTemplateDeploymentFailed"));
5859
}
5960
if (result && result["properties"] && result["properties"]["outputs"] && utils.isNonEmpty(this.taskParameters.deploymentOutputs)) {
@@ -68,6 +69,31 @@ export class DeploymentScopeBase {
6869
}
6970
}
7071

72+
protected checkAndPrintPortalDeploymentURL(error: any) {
73+
if((this.taskParameters.deploymentScope == "Resource Group" || this.taskParameters.deploymentScope == "Subscription") && (!!error && (error.statusCode < 400 || error.statusCode >= 500))) {
74+
tl.error(tl.loc("FindMoreDeploymentDetailsAzurePortal", this.getAzurePortalDeploymentURL()));
75+
}
76+
}
77+
78+
private getAzurePortalDeploymentURL() {
79+
try {
80+
let portalUrl = this.taskParameters.endpointPortalUrl ? this.taskParameters.endpointPortalUrl : "https://portal.azure.com";
81+
portalUrl += "/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/";
82+
83+
let subscriptionSpecificURL = "/subscriptions/" + this.taskParameters.subscriptionId;
84+
if(this.taskParameters.deploymentScope == "Resource Group") {
85+
subscriptionSpecificURL += "/resourceGroups/" + this.taskParameters.resourceGroupName;
86+
}
87+
88+
subscriptionSpecificURL += "/providers/Microsoft.Resources/deployments/" + this.taskParameters.deploymentName;
89+
90+
return portalUrl + subscriptionSpecificURL.replace(/\//g, '%2F');
91+
} catch (error) {
92+
tl.error(error);
93+
return error;
94+
}
95+
}
96+
7197
protected validateDeployment(): Promise<void> {
7298
return new Promise<void>((resolve, reject) => {
7399
console.log(tl.loc("StartingValidation"));

Tasks/AzureResourceManagerTemplateDeploymentV3/task.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 3,
1717
"Minor": 1,
18-
"Patch": 4
18+
"Patch": 5
1919
},
2020
"preview": "true",
2121
"demands": [],
@@ -301,6 +301,7 @@
301301
"ResourceGroupNameNotProvided": "Resource Group name should be provided",
302302
"LocationNotProvided": "Location is required for deployment",
303303
"ARMServiceConnectionScope": "ARM Service Conection deployment scope - %s",
304-
"CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope"
304+
"CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope",
305+
"FindMoreDeploymentDetailsAzurePortal": "Task successfully created an Azure Resource Manager deployment, but the deployment failed. Please see more detailed Azure resource manager deployment logs at: (Please Copy-Paste the link) %s"
305306
}
306307
}

Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": {
1616
"Major": 3,
1717
"Minor": 1,
18-
"Patch": 4
18+
"Patch": 5
1919
},
2020
"preview": "true",
2121
"demands": [],
@@ -301,6 +301,7 @@
301301
"ResourceGroupNameNotProvided": "ms-resource:loc.messages.ResourceGroupNameNotProvided",
302302
"LocationNotProvided": "ms-resource:loc.messages.LocationNotProvided",
303303
"ARMServiceConnectionScope": "ms-resource:loc.messages.ARMServiceConnectionScope",
304-
"CompleteDeploymentModeNotSupported": "ms-resource:loc.messages.CompleteDeploymentModeNotSupported"
304+
"CompleteDeploymentModeNotSupported": "ms-resource:loc.messages.CompleteDeploymentModeNotSupported",
305+
"FindMoreDeploymentDetailsAzurePortal": "ms-resource:loc.messages.FindMoreDeploymentDetailsAzurePortal"
305306
}
306307
}

0 commit comments

Comments
 (0)