From 777976348e92f3a98ff1d8f7c0040a26af204179 Mon Sep 17 00:00:00 2001 From: Nitin Issac Joy Date: Fri, 6 Dec 2019 15:14:47 +0530 Subject: [PATCH] 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 * 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 --- .../resources.resjson/en-US/resources.resjson | 3 ++- .../operations/ResourceGroup.ts | 20 ++++++++++++++ .../AzureResourceGroupDeploymentV2/task.json | 5 ++-- .../task.loc.json | 5 ++-- .../resources.resjson/en-US/resources.resjson | 3 ++- .../operations/DeploymentScopeBase.ts | 26 +++++++++++++++++++ .../task.json | 5 ++-- .../task.loc.json | 5 ++-- 8 files changed, 62 insertions(+), 10 deletions(-) diff --git a/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson index 4235150a614f..e827d5b0bb23 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson @@ -191,5 +191,6 @@ "loc.messages.LogDeploymentName": "Deployment name is %s", "loc.messages.ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.", "loc.messages.DeploymentGroupConfigurationNotSucceeded": "Deployment group configuration did not succeed on one or more Virtual Machine(s): %s", - "loc.messages.DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s" + "loc.messages.DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s", + "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" } \ No newline at end of file diff --git a/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts b/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts index f4456c7455a3..2c94a5915513 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts @@ -514,6 +514,7 @@ export class ResourceGroup { } if (result.error) { this.writeDeploymentErrors(result.error); + tl.error(tl.loc("FindMoreDeploymentDetailsAzurePortal", this.getAzurePortalDeploymentURL())); return reject(tl.loc("CreateTemplateDeploymentFailed")); } else { console.log(tl.loc("ValidDeployment")); @@ -537,6 +538,7 @@ export class ResourceGroup { return this.waitAndPerformAzureDeployment(armClient, deployment, retryCount); } this.writeDeploymentErrors(error); + this.checkAndPrintPortalDeploymentURL(error); return reject(tl.loc("CreateTemplateDeploymentFailed")); } if (result && result["properties"] && result["properties"]["outputs"] && utils.isNonEmpty(this.taskParameters.deploymentOutputs)) { @@ -551,6 +553,12 @@ export class ResourceGroup { } } + protected checkAndPrintPortalDeploymentURL(error: any) { + if(!!error && (error.statusCode < 400 || error.statusCode >= 500)) { + tl.error(tl.loc("FindMoreDeploymentDetailsAzurePortal", this.getAzurePortalDeploymentURL())); + } + } + private async waitAndPerformAzureDeployment(armClient: armResource.ResourceManagementClient, deployment: Deployment, retryCount): Promise { await sleepFor(3); return this.performAzureDeployment(armClient, deployment, retryCount - 1); @@ -569,6 +577,18 @@ export class ResourceGroup { await this.performAzureDeployment(armClient, deployment, 3); } + private getAzurePortalDeploymentURL() { + try { + let portalUrl = this.taskParameters.endpointPortalUrl ? this.taskParameters.endpointPortalUrl : "https://portal.azure.com"; + portalUrl += "/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/"; + let subscriptionSpecificURL = "/subscriptions/" + this.taskParameters.subscriptionId + "/resourceGroups/" + this.taskParameters.resourceGroupName + "/providers/Microsoft.Resources/deployments/" + this.taskParameters.deploymentName; + return portalUrl + subscriptionSpecificURL.replace(/\//g, '%2F'); + } catch (error) { + tl.error(error); + return error; + } + } + private escapeBlockCharacters(str: string): string { return str.replace(/[\[]/g, '$&[]'); } diff --git a/Tasks/AzureResourceGroupDeploymentV2/task.json b/Tasks/AzureResourceGroupDeploymentV2/task.json index 4e6ff31fa6b7..8aa33ac872e9 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/task.json +++ b/Tasks/AzureResourceGroupDeploymentV2/task.json @@ -15,7 +15,7 @@ "version": { "Major": 2, "Minor": 157, - "Patch": 7 + "Patch": 8 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -480,6 +480,7 @@ "LogDeploymentName": "Deployment name is %s", "ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.", "DeploymentGroupConfigurationNotSucceeded": "Deployment group configuration did not succeed on one or more Virtual Machine(s): %s", - "DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s" + "DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s", + "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" } } \ No newline at end of file diff --git a/Tasks/AzureResourceGroupDeploymentV2/task.loc.json b/Tasks/AzureResourceGroupDeploymentV2/task.loc.json index b220da0d16ac..478e7595abba 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/task.loc.json +++ b/Tasks/AzureResourceGroupDeploymentV2/task.loc.json @@ -15,7 +15,7 @@ "version": { "Major": 2, "Minor": 157, - "Patch": 7 + "Patch": 8 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -480,6 +480,7 @@ "LogDeploymentName": "ms-resource:loc.messages.LogDeploymentName", "ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal", "DeploymentGroupConfigurationNotSucceeded": "ms-resource:loc.messages.DeploymentGroupConfigurationNotSucceeded", - "DeploymentGroupConfigurationFailedOnVM": "ms-resource:loc.messages.DeploymentGroupConfigurationFailedOnVM" + "DeploymentGroupConfigurationFailedOnVM": "ms-resource:loc.messages.DeploymentGroupConfigurationFailedOnVM", + "FindMoreDeploymentDetailsAzurePortal": "ms-resource:loc.messages.FindMoreDeploymentDetailsAzurePortal" } } \ No newline at end of file diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureResourceManagerTemplateDeploymentV3/Strings/resources.resjson/en-US/resources.resjson index bb4449642c71..c0a6996c5eed 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/Strings/resources.resjson/en-US/resources.resjson @@ -82,5 +82,6 @@ "loc.messages.ResourceGroupNameNotProvided": "Resource Group name should be provided", "loc.messages.LocationNotProvided": "Location is required for deployment", "loc.messages.ARMServiceConnectionScope": "ARM Service Conection deployment scope - %s", - "loc.messages.CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope" + "loc.messages.CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope", + "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" } \ No newline at end of file diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts index cea703730fec..83c6e8db131a 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts @@ -54,6 +54,7 @@ export class DeploymentScopeBase { return this.waitAndPerformAzureDeployment(retryCount); } utils.writeDeploymentErrors(this.taskParameters, error); + this.checkAndPrintPortalDeploymentURL(error); return reject(tl.loc("CreateTemplateDeploymentFailed")); } if (result && result["properties"] && result["properties"]["outputs"] && utils.isNonEmpty(this.taskParameters.deploymentOutputs)) { @@ -68,6 +69,31 @@ export class DeploymentScopeBase { } } + protected checkAndPrintPortalDeploymentURL(error: any) { + if((this.taskParameters.deploymentScope == "Resource Group" || this.taskParameters.deploymentScope == "Subscription") && (!!error && (error.statusCode < 400 || error.statusCode >= 500))) { + tl.error(tl.loc("FindMoreDeploymentDetailsAzurePortal", this.getAzurePortalDeploymentURL())); + } + } + + private getAzurePortalDeploymentURL() { + try { + let portalUrl = this.taskParameters.endpointPortalUrl ? this.taskParameters.endpointPortalUrl : "https://portal.azure.com"; + portalUrl += "/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/"; + + let subscriptionSpecificURL = "/subscriptions/" + this.taskParameters.subscriptionId; + if(this.taskParameters.deploymentScope == "Resource Group") { + subscriptionSpecificURL += "/resourceGroups/" + this.taskParameters.resourceGroupName; + } + + subscriptionSpecificURL += "/providers/Microsoft.Resources/deployments/" + this.taskParameters.deploymentName; + + return portalUrl + subscriptionSpecificURL.replace(/\//g, '%2F'); + } catch (error) { + tl.error(error); + return error; + } + } + protected validateDeployment(): Promise { return new Promise((resolve, reject) => { console.log(tl.loc("StartingValidation")); diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json index 967fe4c5d4b4..7a74d489419e 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json @@ -15,7 +15,7 @@ "version": { "Major": 3, "Minor": 1, - "Patch": 4 + "Patch": 5 }, "preview": "true", "demands": [], @@ -301,6 +301,7 @@ "ResourceGroupNameNotProvided": "Resource Group name should be provided", "LocationNotProvided": "Location is required for deployment", "ARMServiceConnectionScope": "ARM Service Conection deployment scope - %s", - "CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope" + "CompleteDeploymentModeNotSupported": "Deployment mode 'Complete' is not supported for deployment at '%s' scope", + "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" } } diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json index 9bb806e03ec4..532eb043e41a 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json @@ -15,7 +15,7 @@ "version": { "Major": 3, "Minor": 1, - "Patch": 4 + "Patch": 5 }, "preview": "true", "demands": [], @@ -301,6 +301,7 @@ "ResourceGroupNameNotProvided": "ms-resource:loc.messages.ResourceGroupNameNotProvided", "LocationNotProvided": "ms-resource:loc.messages.LocationNotProvided", "ARMServiceConnectionScope": "ms-resource:loc.messages.ARMServiceConnectionScope", - "CompleteDeploymentModeNotSupported": "ms-resource:loc.messages.CompleteDeploymentModeNotSupported" + "CompleteDeploymentModeNotSupported": "ms-resource:loc.messages.CompleteDeploymentModeNotSupported", + "FindMoreDeploymentDetailsAzurePortal": "ms-resource:loc.messages.FindMoreDeploymentDetailsAzurePortal" } } \ No newline at end of file