From 1173324604c3f61ce52cdcc999f6d4d7ea9ab8f9 Mon Sep 17 00:00:00 2001 From: Tom Bonner <38533968+TomBonnerAtTFL@users.noreply.github.com> Date: Mon, 23 Nov 2020 15:14:30 +0000 Subject: [PATCH] Expand ARM output into Pipeline variables (#13811) * Expand ARM output into Pipeline variables Added code that expands the returned Outputs object into Pipeline variables so they can be used easily in scripts. This fixes issue #13032. * Updated Minor version * Updated Minor version * Updated minor version number * Updated minor version number * Expand variables into separate environment vars Expands the fix for issue #13032. * Updated patch * Updated patch * Added console.log when setting variable * Added console.log when setting variable * Swapped to use spaces to be consistent --- .../operations/ResourceGroup.ts | 14 ++++++++++++++ Tasks/AzureResourceGroupDeploymentV2/task.json | 6 +++--- .../AzureResourceGroupDeploymentV2/task.loc.json | 6 +++--- .../operations/DeploymentScopeBase.ts | 16 +++++++++++++++- .../task.json | 4 ++-- .../task.loc.json | 4 ++-- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts b/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts index d3c823adbb61..743b4583fdd2 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts +++ b/Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts @@ -558,6 +558,20 @@ export class ResourceGroup { return reject(tl.loc("CreateTemplateDeploymentFailed")); } if (result && result["properties"] && result["properties"]["outputs"] && utils.isNonEmpty(this.taskParameters.deploymentOutputs)) { + const setVariablesInObject = (path: string, obj: any) => { + for (var key of Object.keys(obj)) { + if (typeof(obj[key]) === "object") { + setVariablesInObject(`${path}.${key}`, obj[key]); + } + else { + tl.setVariable(`${path}.${key}`, JSON.stringify(obj[key])); + console.log(tl.loc("AddedOutputVariable", `${path}.${key}`)); + } + } + } + if (typeof(result["properties"]["outputs"]) === "object") { + setVariablesInObject(this.taskParameters.deploymentOutputs, result["properties"]["outputs"]); + } tl.setVariable(this.taskParameters.deploymentOutputs, JSON.stringify(result["properties"]["outputs"])); console.log(tl.loc("AddedOutputVariable", this.taskParameters.deploymentOutputs)); } diff --git a/Tasks/AzureResourceGroupDeploymentV2/task.json b/Tasks/AzureResourceGroupDeploymentV2/task.json index 694c80ac73ae..ca62af46d2a7 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/task.json +++ b/Tasks/AzureResourceGroupDeploymentV2/task.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 175, - "Patch": 2 + "Minor": 179, + "Patch": 0 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -488,4 +488,4 @@ "DeploymentGroupConfigurationFailedOnVM": "Failure for Virtual Machine '%s': %s", "TroubleshootingGuide": "Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting" } -} \ No newline at end of file +} diff --git a/Tasks/AzureResourceGroupDeploymentV2/task.loc.json b/Tasks/AzureResourceGroupDeploymentV2/task.loc.json index 966ae4f011c9..d9676947739d 100644 --- a/Tasks/AzureResourceGroupDeploymentV2/task.loc.json +++ b/Tasks/AzureResourceGroupDeploymentV2/task.loc.json @@ -14,8 +14,8 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 175, - "Patch": 2 + "Minor": 179, + "Patch": 0 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -488,4 +488,4 @@ "DeploymentGroupConfigurationFailedOnVM": "ms-resource:loc.messages.DeploymentGroupConfigurationFailedOnVM", "TroubleshootingGuide": "ms-resource:loc.messages.TroubleshootingGuide" } -} \ No newline at end of file +} diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts index f14f599a26d6..5fa8d41a6180 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/operations/DeploymentScopeBase.ts @@ -71,6 +71,20 @@ export class DeploymentScopeBase { return reject(tl.loc("CreateTemplateDeploymentFailed")); } if (result && result["properties"] && result["properties"]["outputs"] && utils.isNonEmpty(this.taskParameters.deploymentOutputs)) { + const setVariablesInObject = (path: string, obj: any) => { + for (var key of Object.keys(obj)) { + if (typeof(obj[key]) === "object") { + setVariablesInObject(`${path}.${key}`, obj[key]); + } + else { + tl.setVariable(`${path}.${key}`, JSON.stringify(obj[key])); + console.log(tl.loc("AddedOutputVariable", `${path}.${key}`)); + } + } + } + if (typeof(result["properties"]["outputs"]) === "object") { + setVariablesInObject(this.taskParameters.deploymentOutputs, result["properties"]["outputs"]); + } tl.setVariable(this.taskParameters.deploymentOutputs, JSON.stringify(result["properties"]["outputs"])); console.log(tl.loc("AddedOutputVariable", this.taskParameters.deploymentOutputs)); } @@ -165,4 +179,4 @@ export class DeploymentScopeBase { await sleepFor(3); return this.performAzureDeployment(retryCount - 1); } -} \ No newline at end of file +} diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json index 83e02e3d1235..1aa7e89b6f2e 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.json @@ -15,7 +15,7 @@ "version": { "Major": 3, "Minor": 179, - "Patch": 0 + "Patch": 1 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -311,4 +311,4 @@ "TemplateValidationFailure": "Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. %s. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax", "TroubleshootingGuide": "Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting" } -} \ No newline at end of file +} diff --git a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json index cea047cd62e4..94d573c7646f 100644 --- a/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json +++ b/Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json @@ -15,7 +15,7 @@ "version": { "Major": 3, "Minor": 179, - "Patch": 0 + "Patch": 1 }, "demands": [], "minimumAgentVersion": "2.119.1", @@ -311,4 +311,4 @@ "TemplateValidationFailure": "ms-resource:loc.messages.TemplateValidationFailure", "TroubleshootingGuide": "ms-resource:loc.messages.TroubleshootingGuide" } -} \ No newline at end of file +}