Skip to content

Commit

Permalink
Expand ARM output into Pipeline variables (#13811)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TomBonnerAtTFL committed Nov 23, 2020
1 parent f596b2a commit 1173324
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
14 changes: 14 additions & 0 deletions Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts
Expand Up @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions Tasks/AzureResourceGroupDeploymentV2/task.json
Expand Up @@ -14,8 +14,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 175,
"Patch": 2
"Minor": 179,
"Patch": 0
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -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"
}
}
}
6 changes: 3 additions & 3 deletions Tasks/AzureResourceGroupDeploymentV2/task.loc.json
Expand Up @@ -14,8 +14,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 175,
"Patch": 2
"Minor": 179,
"Patch": 0
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -488,4 +488,4 @@
"DeploymentGroupConfigurationFailedOnVM": "ms-resource:loc.messages.DeploymentGroupConfigurationFailedOnVM",
"TroubleshootingGuide": "ms-resource:loc.messages.TroubleshootingGuide"
}
}
}
Expand Up @@ -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));
}
Expand Down Expand Up @@ -165,4 +179,4 @@ export class DeploymentScopeBase {
await sleepFor(3);
return this.performAzureDeployment(retryCount - 1);
}
}
}
4 changes: 2 additions & 2 deletions Tasks/AzureResourceManagerTemplateDeploymentV3/task.json
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 3,
"Minor": 179,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -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"
}
}
}
4 changes: 2 additions & 2 deletions Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 3,
"Minor": 179,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -311,4 +311,4 @@
"TemplateValidationFailure": "ms-resource:loc.messages.TemplateValidationFailure",
"TroubleshootingGuide": "ms-resource:loc.messages.TroubleshootingGuide"
}
}
}

0 comments on commit 1173324

Please sign in to comment.