From 12c4e3fc82e8d46c14531a7834d033bf32b07f93 Mon Sep 17 00:00:00 2001 From: Nitin Issac Joy Date: Thu, 5 Dec 2019 18:58:58 +0530 Subject: [PATCH] Removing ARGV2 version to see if test runs fine --- .../resources.resjson/en-US/resources.resjson | 2 -- .../Tests/EnablePrereq.ts | 1 - .../Tests/VMOperations.ts | 1 - .../Tests/addVSTSExtension.ts | 1 - .../Tests/createOrUpdate.ts | 1 - .../Tests/deleteResourceGroup.ts | 1 - .../Tests/deleteVSTSExtension.ts | 1 - .../Tests/selectResourceGroup.ts | 1 - .../models/DeployAzureRG.ts | 14 ---------- .../operations/ResourceGroup.ts | 26 +++++-------------- .../AzureResourceGroupDeploymentV2/task.json | 4 +-- .../task.loc.json | 4 +-- 12 files changed, 8 insertions(+), 49 deletions(-) diff --git a/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson index 4a30c67df548..e827d5b0bb23 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureResourceGroupDeploymentV2/Strings/resources.resjson/en-US/resources.resjson @@ -192,7 +192,5 @@ "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.ServicePrincipalRoleAssignmentDetails": "Please make sure the Service Principal with name %s is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal", - "loc.messages.ServicePrincipalFetchFailed": "Error while fetching Service Principal details: %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/Tests/EnablePrereq.ts b/Tasks/AzureResourceGroupDeploymentV2/Tests/EnablePrereq.ts index 7cdac229d156..30a58c99053c 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Tests/EnablePrereq.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/Tests/EnablePrereq.ts @@ -22,7 +22,6 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALKEY"] = "key"; process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID"] = "tenant"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID"] = "sId"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME"] = "sName"; -process.env["ENDPOINT_DATA_AzureRM_GRAPHURL"] = "https://graph.windows.net/"; process.env["ENDPOINT_URL_AzureRM"] = "https://management.azure.com/"; process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.windows.net/"; diff --git a/Tasks/AzureResourceGroupDeploymentV2/Tests/VMOperations.ts b/Tasks/AzureResourceGroupDeploymentV2/Tests/VMOperations.ts index 66c1ae1b848a..10c200b13aed 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Tests/VMOperations.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/Tests/VMOperations.ts @@ -15,7 +15,6 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALKEY"] = "key"; process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID"] = "tenant"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID"] = "sId"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME"] = "sName"; -process.env["ENDPOINT_DATA_AzureRM_GRAPHURL"] = "https://graph.windows.net/"; process.env["ENDPOINT_URL_AzureRM"] = "https://management.azure.com/"; process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.windows.net/"; process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = "https://management.azure.com"; diff --git a/Tasks/AzureResourceGroupDeploymentV2/Tests/addVSTSExtension.ts b/Tasks/AzureResourceGroupDeploymentV2/Tests/addVSTSExtension.ts index 02dd0b915466..9fe7bc453741 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Tests/addVSTSExtension.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/Tests/addVSTSExtension.ts @@ -27,7 +27,6 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALKEY"] = "key"; process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID"] = "tenant"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID"] = "sId"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME"] = "sName"; -process.env["ENDPOINT_DATA_AzureRM_GRAPHURL"] = "https://graph.windows.net/";; process.env["ENDPOINT_URL_AzureRM"] = "https://management.azure.com/"; process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.windows.net/"; process.env["ENDPOINT_URL_PatEndpoint"] = "https://testking123.visualstudio.com"; diff --git a/Tasks/AzureResourceGroupDeploymentV2/Tests/createOrUpdate.ts b/Tasks/AzureResourceGroupDeploymentV2/Tests/createOrUpdate.ts index 47ba3dccf929..b3c5a38a2038 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Tests/createOrUpdate.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/Tests/createOrUpdate.ts @@ -23,7 +23,6 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALKEY"] = "key"; process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID"] = "tenant"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID"] = "sId"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME"] = "sName"; -process.env["ENDPOINT_DATA_AzureRM_GRAPHURL"] = "https://graph.windows.net/"; process.env["ENDPOINT_URL_AzureRM"] = "https://management.azure.com/"; process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.windows.net/"; process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = "https://management.azure.com"; diff --git a/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteResourceGroup.ts b/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteResourceGroup.ts index 7eb604dbb0a6..ffe869ac8547 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteResourceGroup.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteResourceGroup.ts @@ -15,7 +15,6 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALKEY"] = "key"; process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID"] = "tenant"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID"] = "sId"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME"] = "sName"; -process.env["ENDPOINT_DATA_AzureRM_GRAPHURL"] = "https://graph.windows.net/"; process.env["ENDPOINT_URL_AzureRM"] = "https://management.azure.com/"; process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.windows.net/"; process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = "https://management.azure.com"; diff --git a/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteVSTSExtension.ts b/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteVSTSExtension.ts index 23586ed330a9..9698ca961ed0 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteVSTSExtension.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/Tests/deleteVSTSExtension.ts @@ -16,7 +16,6 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALKEY"] = "key"; process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID"] = "tenant"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID"] = "sId"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME"] = "sName"; -process.env["ENDPOINT_DATA_AzureRM_GRAPHURL"] = "https://graph.windows.net/"; process.env["ENDPOINT_URL_AzureRM"] = "https://management.azure.com/"; process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.windows.net/"; process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = "https://management.azure.com"; diff --git a/Tasks/AzureResourceGroupDeploymentV2/Tests/selectResourceGroup.ts b/Tasks/AzureResourceGroupDeploymentV2/Tests/selectResourceGroup.ts index d640d5c49b21..08168543a1aa 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/Tests/selectResourceGroup.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/Tests/selectResourceGroup.ts @@ -17,7 +17,6 @@ process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALKEY"] = "key"; process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID"] = "tenant"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID"] = "sId"; process.env["ENDPOINT_DATA_AzureRM_SUBSCRIPTIONNAME"] = "sName"; -process.env["ENDPOINT_DATA_AzureRM_GRAPHURL"] = "https://graph.windows.net/"; process.env["ENDPOINT_URL_AzureRM"] = "https://management.azure.com/"; process.env["ENDPOINT_DATA_AzureRM_ENVIRONMENTAUTHORITYURL"] = "https://login.windows.net/"; process.env["ENDPOINT_DATA_AzureRM_ACTIVEDIRECTORYSERVICEENDPOINTRESOURCEID"] = "https://management.azure.com"; diff --git a/Tasks/AzureResourceGroupDeploymentV2/models/DeployAzureRG.ts b/Tasks/AzureResourceGroupDeploymentV2/models/DeployAzureRG.ts index 8493640d7550..78122bb28e37 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/models/DeployAzureRG.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/models/DeployAzureRG.ts @@ -66,7 +66,6 @@ export class AzureRGTaskParameters { public deploymentName: string; public deploymentMode: string; public credentials: msRestAzure.ApplicationTokenCredentials; - public graphCredentials: msRestAzure.ApplicationTokenCredentials; public deploymentGroupProjectName = ""; public tokenCredentials: TokenCredentials; public deploymentOutputs: string; @@ -96,18 +95,6 @@ export class AzureRGTaskParameters { throw (msg); } } - - private _getAzureADGraphCredentials(connectedService: string): msRestAzure.ApplicationTokenCredentials { - var servicePrincipalId: string = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false); - var servicePrincipalKey: string = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalkey", false); - var tenantId: string = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false); - var envAuthorityUrl: string = tl.getEndpointDataParameter(connectedService, 'environmentauthorityurl', false); - envAuthorityUrl = (envAuthorityUrl != null) ? envAuthorityUrl : "https://login.windows.net/"; - var activeDirectoryResourceId: string = tl.getEndpointDataParameter(connectedService, 'graphUrl', false); - activeDirectoryResourceId = (activeDirectoryResourceId != null) ? activeDirectoryResourceId : "https://graph.windows.net/"; - var credentials = new msRestAzure.ApplicationTokenCredentials(servicePrincipalId, tenantId, servicePrincipalKey, activeDirectoryResourceId, envAuthorityUrl, activeDirectoryResourceId, false); - return credentials; - } private async getARMCredentials(connectedService: string): Promise { var azureEndpoint = await new AzureRMEndpoint(connectedService).getEndpoint(); @@ -153,7 +140,6 @@ export class AzureRGTaskParameters { this.deploymentName = tl.getInput("deploymentName"); this.deploymentMode = tl.getInput("deploymentMode"); this.credentials = await this.getARMCredentials(this.connectedService); - this.graphCredentials = this._getAzureADGraphCredentials(this.connectedService); this.deploymentGroupProjectName = tl.getInput("project"); this.deploymentOutputs = tl.getInput("deploymentOutputs"); this.addSpnToEnvironment = tl.getBoolInput("addSpnToEnvironment", false); diff --git a/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts b/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts index 7b8f958dcd66..a766e8f12a27 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts @@ -2,7 +2,6 @@ import path = require("path"); import tl = require("azure-pipelines-task-lib/task"); import fs = require("fs"); import util = require("util"); -import azureGraph = require("azure-arm-rest-v2/azure-graph"); import env = require("./Environment"); import deployAzureRG = require("../models/DeployAzureRG"); import armResource = require("azure-arm-rest-v2/azure-arm-resource"); @@ -524,7 +523,7 @@ export class ResourceGroup { }); } - private async performAzureDeployment(armClient: armResource.ResourceManagementClient, deployment: Deployment, retryCount = 0, spnName: string): Promise { + private async performAzureDeployment(armClient: armResource.ResourceManagementClient, deployment: Deployment, retryCount = 0): Promise { if (deployment.properties["mode"] === "Validation") { return this.validateDeployment(armClient, deployment); } else { @@ -535,12 +534,10 @@ export class ResourceGroup { armClient.deployments.createOrUpdate(this.taskParameters.deploymentName, deployment, (error, result, request, response) => { if (error) { if(error.code == "ResourceGroupNotFound" && retryCount > 0){ - return this.waitAndPerformAzureDeployment(armClient, deployment, retryCount, spnName); + return this.waitAndPerformAzureDeployment(armClient, deployment, retryCount); } this.writeDeploymentErrors(error); - if(error.statusCode == 403) { - tl.error(tl.loc("ServicePrincipalRoleAssignmentDetails", spnName, this.taskParameters.resourceGroupName)); - } + this.checkAndPrintPortalDeploymentURL(); return reject(tl.loc("CreateTemplateDeploymentFailed")); } @@ -560,9 +557,9 @@ export class ResourceGroup { tl.error(tl.loc("FindMoreDeploymentDetailsAzurePortal", this.getAzurePortalDeploymentURL())); } - private async waitAndPerformAzureDeployment(armClient: armResource.ResourceManagementClient, deployment: Deployment, retryCount, spnName: string): Promise { + private async waitAndPerformAzureDeployment(armClient: armResource.ResourceManagementClient, deployment: Deployment, retryCount): Promise { await sleepFor(3); - return this.performAzureDeployment(armClient, deployment, retryCount - 1, spnName); + return this.performAzureDeployment(armClient, deployment, retryCount - 1); } private async createTemplateDeployment(armClient: armResource.ResourceManagementClient) { @@ -575,18 +572,7 @@ export class ResourceGroup { } else { throw new Error(tl.loc("InvalidTemplateLocation")); } - await this.performAzureDeployment(armClient, deployment, 3, await this.getServicePrincipalName()); - } - - protected async getServicePrincipalName(): Promise { - try { - var graphClient: azureGraph.GraphManagementClient = new azureGraph.GraphManagementClient(this.taskParameters.graphCredentials); - var servicePrincipalObject = await graphClient.servicePrincipals.GetServicePrincipal(null); - return !!servicePrincipalObject ? servicePrincipalObject.appDisplayName : ""; - } catch (error) { - tl.debug(tl.loc("ServicePrincipalFetchFailed", error)); - return ""; - } + await this.performAzureDeployment(armClient, deployment, 3); } private getAzurePortalDeploymentURL() { diff --git a/Tasks/AzureResourceGroupDeploymentV2/task.json b/Tasks/AzureResourceGroupDeploymentV2/task.json index 36b75b8a2322..0bdc29e93040 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/task.json +++ b/Tasks/AzureResourceGroupDeploymentV2/task.json @@ -15,7 +15,7 @@ "version": { "Major": 2, "Minor": 157, - "Patch": 11 + "Patch": 10 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -481,8 +481,6 @@ "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", - "ServicePrincipalRoleAssignmentDetails": "Please make sure the Service Principal with name %s is assigned the right roles for the Resource Group %s. Follow the link for more details: https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal", - "ServicePrincipalFetchFailed": "Error while fetching Service Principal details: %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 7ad7443ddce3..8650ca8fbe7f 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/task.loc.json +++ b/Tasks/AzureResourceGroupDeploymentV2/task.loc.json @@ -15,7 +15,7 @@ "version": { "Major": 2, "Minor": 157, - "Patch": 11 + "Patch": 10 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -481,8 +481,6 @@ "ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal", "DeploymentGroupConfigurationNotSucceeded": "ms-resource:loc.messages.DeploymentGroupConfigurationNotSucceeded", "DeploymentGroupConfigurationFailedOnVM": "ms-resource:loc.messages.DeploymentGroupConfigurationFailedOnVM", - "ServicePrincipalRoleAssignmentDetails": "ms-resource:loc.messages.ServicePrincipalRoleAssignmentDetails", - "ServicePrincipalFetchFailed": "ms-resource:loc.messages.ServicePrincipalFetchFailed", "FindMoreDeploymentDetailsAzurePortal": "ms-resource:loc.messages.FindMoreDeploymentDetailsAzurePortal" } } \ No newline at end of file