Skip to content

Commit

Permalink
Outputs section for deploy RG task (#6129)
Browse files Browse the repository at this point in the history
* Updating output variable for ARG task

* Moving to a different section

* Added test

* Fixing L0
  • Loading branch information
thesattiraju committed Jan 9, 2018
1 parent e5681f0 commit 4216246
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 19 deletions.
Expand Up @@ -7,6 +7,7 @@
"loc.group.displayName.AzureDetails": "Azure Details",
"loc.group.displayName.Template": "Template",
"loc.group.displayName.AdvancedDeploymentOptions": "Advanced deployment options for virtual machines",
"loc.group.displayName.Outputs": "Outputs",
"loc.input.label.ConnectedServiceName": "Azure subscription",
"loc.input.help.ConnectedServiceName": "Select the Azure Resource Manager subscription for the deployment.",
"loc.input.label.action": "Action",
Expand Down Expand Up @@ -40,6 +41,8 @@
"loc.input.help.copyAzureVMTags": "Choose if the tags configured on the Azure VM need to be copied to the corresponding Deployment Group agent. <br><br>​By default all Azure tags will be copied following the format “Key: Value”. Example: An Azure Tag “Role : Web” would be copied as-is to the Agent machine. <br><br>For more information on how tag Azure resources refer to [link](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-using-tags​)",
"loc.input.label.outputVariable": "VM details for WinRM",
"loc.input.help.outputVariable": "Provide a name for the variable for the resource group. The variable can be used as $(variableName) to refer to the resource group in subsequent tasks like in the PowerShell on Target Machines task for deploying applications. <br>Valid only when the selected action is Create, Update or Select, and required when an existing resource group is selected.",
"loc.input.label.deploymentOutputs": "Deployment outputs",
"loc.input.help.deploymentOutputs": "Provide a name for the variable for the output variable which will contain the outputs section of the current deployment object in string format. You can use the “ConvertFrom-Json” PowerShell cmdlet to parse the JSON object and access the individual output values.",
"loc.messages.CheckResourceGroupExistence": "Checking if the following resource group exists: %s.",
"loc.messages.ResourceGroupStatusFetchFailed": "Failed to check the resource group status. Error: %s.",
"loc.messages.ResourceGroupStatus": "Resource group exists: %s.",
Expand Down Expand Up @@ -161,7 +164,7 @@
"loc.messages.ProvisioningStatusOfExtensionIsNotSucceeded": "Provisioning State of WinRMCustomScriptExtension is not succeeded on vm: '%s'.",
"loc.messages.ListingOfExtensionsFailed": "Failed to list the extensions for the vm: '%s'. Error '%s'",
"loc.messages.ExtensionNotFound": "Extension not found on the vm: %s",
"loc.messages.AddedOutputVariable": "Updated output variable 'DeploymentOutputs', which contains the outputs section of the current deployment object in string format. Follow this link: https://go.microsoft.com/fwlink/?linkid=853539 to learn how to use it in your defintion",
"loc.messages.AddedOutputVariable": "Updated output variable '%s', which contains the outputs section of the current deployment object in string format.",
"loc.messages.UnableToFetchAuthorityURL": "Unable to fetch authority url.",
"loc.messages.UnableToFetchActiveDirectory": "Unable to fetch active directory resource id.",
"loc.messages.SpecifiedAzureRmEndpointIsInvalid": "Specified AzureRm endpoint url : '{0}' is invalid.",
Expand Down
21 changes: 20 additions & 1 deletion Tasks/AzureResourceGroupDeployment/Tests/L0.ts
Expand Up @@ -446,7 +446,26 @@ describe('Azure Resource Group Deployment', function () {
try {
assert(tr.succeeded, "Should have succeeded");
assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk");
// assert(tr.stdout.indexOf("AddedOutputVariable") > 0, "should have set task output variable");
assert(tr.stdout.indexOf("set ") < 0, "deploymentsOutput should not have been updated");
done();
}
catch (error) {
console.log("STDERR", tr.stderr);
console.log("STDOUT", tr.stdout);
done(error);
}
});
it('Successfully triggered createOrUpdate deployment and updated deploymentOutputs', (done) => {
let tp = path.join(__dirname, 'createOrUpdate.js');
process.env["csmFile"] = "CSM.json";
process.env["csmParametersFile"] = "CSM.json";
process.env["deploymentOutputs"] = "someVar";
let tr = new ttm.MockTestRunner(tp);
tr.run();
try {
assert(tr.succeeded, "Should have succeeded");
assert(tr.stdout.indexOf("deployments.createOrUpdate is called") > 0, "deployments.createOrUpdate function should have been called from azure-sdk");
assert(tr.stdout.indexOf("set someVar") >= 0, "deploymentsOutput should have been updated");
done();
}
catch (error) {
Expand Down
1 change: 1 addition & 0 deletions Tasks/AzureResourceGroupDeployment/Tests/createOrUpdate.ts
Expand Up @@ -15,6 +15,7 @@ tr.setInput("overrideParameters", "");
tr.setInput("deploymentMode", "Complete");
tr.setInput("enableDeploymentPrerequisites", "None");
tr.setInput("csmParametersFile", process.env["csmParametersFile"]);
tr.setInput("deploymentOutputs", !!process.env["deploymentOutputs"] ? process.env["deploymentOutputs"] : "");

process.env["ENDPOINT_AUTH_AzureRM"] = "{\"parameters\":{\"serviceprincipalid\":\"id\",\"serviceprincipalkey\":\"key\",\"tenantid\":\"tenant\"},\"scheme\":\"ServicePrincipal\"}";
process.env["ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALID"] = "id";
Expand Down
2 changes: 2 additions & 0 deletions Tasks/AzureResourceGroupDeployment/models/DeployAzureRG.ts
Expand Up @@ -50,6 +50,7 @@ export class AzureRGTaskParameters {
public credentials: msRestAzure.ApplicationTokenCredentials;
public deploymentGroupProjectName = "";
public tokenCredentials: TokenCredentials;
public deploymentOutputs: string;

private getVSTSPatToken(deploymentGroupEndpointName: string): TokenCredentials {
var endpointAuth = tl.getEndpointAuthorization(deploymentGroupEndpointName, true);
Expand Down Expand Up @@ -135,6 +136,7 @@ export class AzureRGTaskParameters {
this.deploymentMode = tl.getInput("deploymentMode");
this.credentials = await this.getARMCredentials(connectedService);
this.deploymentGroupProjectName = tl.getInput("project");
this.deploymentOutputs = tl.getInput("deploymentOutputs");
return this;
} catch (error) {
throw new Error(tl.loc("ARGD_ConstructorFailed", error.message));
Expand Down
Expand Up @@ -439,10 +439,11 @@ export class ResourceGroup {
this.writeDeploymentErrors(error);
return reject(tl.loc("CreateTemplateDeploymentFailed"));
}
// if (result && result["properties"] && result["properties"]["outputs"]) {
// tl.command("task.setvariable", { "isOutput": "true", "variable": "DeploymentOutputs" }, JSON.stringify(result["properties"]["outputs"]));
// console.log(tl.loc("AddedOutputVariable"));
// }
if (result && result["properties"] && result["properties"]["outputs"] && utils.isNonEmpty(this.taskParameters.deploymentOutputs)) {
tl.setVariable(this.taskParameters.deploymentOutputs, JSON.stringify(result["properties"]["outputs"]));
console.log(tl.loc("AddedOutputVariable", this.taskParameters.deploymentOutputs));
}

console.log(tl.loc("CreateTemplateDeploymentSucceeded"));
resolve();
});
Expand Down
23 changes: 16 additions & 7 deletions Tasks/AzureResourceGroupDeployment/task.json
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 129,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand All @@ -35,6 +35,12 @@
"displayName": "Advanced deployment options for virtual machines",
"isExpanded": true,
"visibleRule": "action = Create Or Update Resource Group || action = Select Resource Group"
},
{
"name": "Outputs",
"displayName": "Outputs",
"isExpanded": true,
"visibleRule": "action = Create Or Update Resource Group"
}
],
"inputs": [
Expand Down Expand Up @@ -243,12 +249,15 @@
"groupName": "AdvancedDeploymentOptions",
"visibleRule": "enableDeploymentPrerequisites = ConfigureVMwithWinRM || enableDeploymentPrerequisites = None",
"helpMarkDown": "Provide a name for the variable for the resource group. The variable can be used as $(variableName) to refer to the resource group in subsequent tasks like in the PowerShell on Target Machines task for deploying applications. <br>Valid only when the selected action is Create, Update or Select, and required when an existing resource group is selected."
}
],
"OutputVariables": [
},
{
"name": "DeploymentOutputs",
"description": "This task output variable will contain the outputs section of the current deployment object in string format. You can use the “ConvertFrom-Json” PowerShell cmdlet to parse the JSON object and access the individual output values."
"name": "deploymentOutputs",
"type": "string",
"label": "Deployment outputs",
"required": false,
"defaultValue": "",
"groupName": "Outputs",
"helpMarkDown": "Provide a name for the variable for the output variable which will contain the outputs section of the current deployment object in string format. You can use the “ConvertFrom-Json” PowerShell cmdlet to parse the JSON object and access the individual output values."
}
],
"dataSourceBindings": [
Expand Down Expand Up @@ -406,7 +415,7 @@
"ProvisioningStatusOfExtensionIsNotSucceeded": "Provisioning State of WinRMCustomScriptExtension is not succeeded on vm: '%s'.",
"ListingOfExtensionsFailed": "Failed to list the extensions for the vm: '%s'. Error '%s'",
"ExtensionNotFound": "Extension not found on the vm: %s",
"AddedOutputVariable": "Updated output variable 'DeploymentOutputs', which contains the outputs section of the current deployment object in string format. Follow this link: https://go.microsoft.com/fwlink/?linkid=853539 to learn how to use it in your defintion",
"AddedOutputVariable": "Updated output variable '%s', which contains the outputs section of the current deployment object in string format.",
"UnableToFetchAuthorityURL": "Unable to fetch authority url.",
"UnableToFetchActiveDirectory": "Unable to fetch active directory resource id.",
"SpecifiedAzureRmEndpointIsInvalid": "Specified AzureRm endpoint url : '{0}' is invalid.",
Expand Down
21 changes: 15 additions & 6 deletions Tasks/AzureResourceGroupDeployment/task.loc.json
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 129,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand All @@ -35,6 +35,12 @@
"displayName": "ms-resource:loc.group.displayName.AdvancedDeploymentOptions",
"isExpanded": true,
"visibleRule": "action = Create Or Update Resource Group || action = Select Resource Group"
},
{
"name": "Outputs",
"displayName": "ms-resource:loc.group.displayName.Outputs",
"isExpanded": true,
"visibleRule": "action = Create Or Update Resource Group"
}
],
"inputs": [
Expand Down Expand Up @@ -243,12 +249,15 @@
"groupName": "AdvancedDeploymentOptions",
"visibleRule": "enableDeploymentPrerequisites = ConfigureVMwithWinRM || enableDeploymentPrerequisites = None",
"helpMarkDown": "ms-resource:loc.input.help.outputVariable"
}
],
"OutputVariables": [
},
{
"name": "DeploymentOutputs",
"description": "This task output variable will contain the outputs section of the current deployment object in string format. You can use the “ConvertFrom-Json” PowerShell cmdlet to parse the JSON object and access the individual output values."
"name": "deploymentOutputs",
"type": "string",
"label": "ms-resource:loc.input.label.deploymentOutputs",
"required": false,
"defaultValue": "",
"groupName": "Outputs",
"helpMarkDown": "ms-resource:loc.input.help.deploymentOutputs"
}
],
"dataSourceBindings": [
Expand Down

0 comments on commit 4216246

Please sign in to comment.