Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checkbox for JSONStringify #18526

Merged
6 commits merged into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Tasks/AzureResourceGroupDeploymentV2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,35 @@ The following parameters are shown when the selected action is to create or upda
sed -e 's/]"/]/g'`
sa_name=`echo $var | jq -r .storageAccountName.value`
echo $sa_name

```
In case, you're accessing individual output values directly, values are being set after being converted via JSON.Stringify. To change this behavior, `Use individual output values without JSON.Stringify applied` checkbox can be used:

Example:
Let's assume, we've `outputvalue` as output of the deployment.

`Use individual output values without JSON.Stringify applied` set to `false (default)`
```
outputvalue => JSON.stringify(outputvalue) => "outputvalue":

// setting variable as JSON.stringify's result
##vso[task.setvariable variable=taskdeploymentoutputname.outputkey]"outputvalue"

// variable will be read as JSON.stringify's result
$(outputvalue) => "outputvalue"
```

`Use individual output values without JSON.Stringify applied` set to `true`
```
outputvalue => no operation:

// setting variable as it is
##vso[task.setvariable variable=taskdeploymentoutputname.outputkey]outputvalue

// variable will be read as it is
$(outputvalue) => outputvalue
```

### Advanced deployment options for virtual machines:

These options would be applicable only when the Resource group contains virtual machines.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"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. For more details refer to [this](https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceGroupDeploymentV2#deployment-outputs)",
"loc.input.label.addSpnToEnvironment": "Access service principal details in override parameters",
"loc.input.help.addSpnToEnvironment": "Adds service principal id and key of the Azure endpoint you chose to the script's execution environment. You can use these variables: `$servicePrincipalId` and `$servicePrincipalKey` in your override parameters like `-key $servicePrincipalKey`",
"loc.input.label.useWithoutJSON": "Use individual output values without JSON.Stringify applied",
"loc.input.help.useWithoutJSON": "Individual output values are being converted via JSON.Stringify by default. If you want to use the output values as it is without converting them via JSON.Stringify, enable this option. For more details refer to [this](https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceGroupDeploymentV2#deployment-outputs)",
"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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class AzureRGTaskParameters {
public agentServiceUserCredentials: AgentServiceUserCredentials;
public runAgentServiceAsUser: boolean;
public addSpnToEnvironment: boolean;
public useWithoutJSON: boolean;
public connectedService: string;
public authScheme: string;

Expand Down Expand Up @@ -152,6 +153,8 @@ export class AzureRGTaskParameters {
this.deploymentGroupProjectName = tl.getInput("project");
this.deploymentOutputs = tl.getInput("deploymentOutputs");
this.addSpnToEnvironment = tl.getBoolInput("addSpnToEnvironment", false);
this.useWithoutJSON = tl.getBoolInput("useWithoutJSON", false);

return this;
} catch (error) {
throw new Error(tl.loc("ARGD_ConstructorFailed", error.message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export class ResourceGroup {
setVariablesInObject(`${path}.${key}`, obj[key]);
}
else {
console.log(`##vso[task.setvariable variable=${path}.${key};]` + JSON.stringify(obj[key]));
console.log(`##vso[task.setvariable variable=${path}.${key};]` + (this.taskParameters.useWithoutJSON ? obj[key] : JSON.stringify(obj[key])));
console.log(tl.loc("AddedOutputVariable", `${path}.${key}`));
}
}
Expand Down
11 changes: 10 additions & 1 deletion Tasks/AzureResourceGroupDeploymentV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 224,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -306,6 +306,15 @@
"required": false,
"helpMarkDown": "Adds service principal id and key of the Azure endpoint you chose to the script's execution environment. You can use these variables: `$servicePrincipalId` and `$servicePrincipalKey` in your override parameters like `-key $servicePrincipalKey`",
"groupName": "Advanced"
},
{
"name": "useWithoutJSON",
"type": "boolean",
"label": "Use individual output values without JSON.Stringify applied",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Individual output values are being converted via JSON.Stringify by default. If you want to use the output values as it is without converting them via JSON.Stringify, enable this option. For more details refer to [this](https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceGroupDeploymentV2#deployment-outputs)",
"groupName": "Advanced"
}
],
"dataSourceBindings": [
Expand Down
11 changes: 10 additions & 1 deletion Tasks/AzureResourceGroupDeploymentV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 224,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -306,6 +306,15 @@
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.addSpnToEnvironment",
"groupName": "Advanced"
},
{
"name": "useWithoutJSON",
"type": "boolean",
"label": "ms-resource:loc.input.label.useWithoutJSON",
"defaultValue": "false",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.useWithoutJSON",
"groupName": "Advanced"
}
],
"dataSourceBindings": [
Expand Down
27 changes: 27 additions & 0 deletions Tasks/AzureResourceManagerTemplateDeploymentV3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,33 @@ The parameters of the task are described in details, including examples, to show
echo $sa_name
```

In case, you're accessing individual output values directly, values are being set after being converted via JSON.Stringify. To change this behavior, `Use individual output values without JSON.Stringify applied` checkbox can be used:

Example:
Let's assume, we've `outputvalue` as output of the deployment.

`Use individual output values without JSON.Stringify applied` set to `false (default)`
```
outputvalue => JSON.stringify(outputvalue) => "outputvalue":

// setting variable as JSON.stringify's result
##vso[task.setvariable variable=taskdeploymentoutputname.outputkey]"outputvalue"

// variable will be read as JSON.stringify's result
$(outputvalue) => "outputvalue"
```

`Use individual output values without JSON.Stringify applied` set to `true`
```
outputvalue => no operation:

// setting variable as it is
##vso[task.setvariable variable=taskdeploymentoutputname.outputkey]outputvalue

// variable will be read as it is
$(outputvalue) => outputvalue
```

### Supported Azure and AzureRM module versions:
| Azure Pipelines/TFS Release | Recommended Azure Version | Other Supported Versions |
|:------------------:|:---------------------------:|:-------------------------:|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"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. For more details refer to [this](https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceManagerTemplateDeploymentV3#deployment-outputs)",
"loc.input.label.addSpnToEnvironment": "Access service principal details in override parameters",
"loc.input.help.addSpnToEnvironment": "Adds service principal id and key of the Azure endpoint you chose to the script's execution environment. You can use these variables: `$servicePrincipalId` and `$servicePrincipalKey` in your override parameters like `-key $servicePrincipalKey`",
"loc.input.label.useWithoutJSON": "Use individual output values without JSON.Stringify applied",
"loc.input.help.useWithoutJSON": "Individual output values are being converted via JSON.Stringify by default. If you want to use the output values as it is without converting them via JSON.Stringify, enable this option. For more details refer to [this](https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceManagerTemplateDeploymentV3#deployment-outputs)",
"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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class TaskParameters {
public graphCredentials: msRestAzure.ApplicationTokenCredentials;
public deploymentOutputs: string;
public addSpnToEnvironment: boolean;
public useWithoutJSON: boolean;
public connectedService: string;
public deploymentScope: string;
public managementGroupId: string;
Expand Down Expand Up @@ -118,6 +119,7 @@ export class TaskParameters {
this.graphCredentials = await this.getGraphCredentials(this.connectedService);
this.deploymentOutputs = tl.getInput("deploymentOutputs");
this.addSpnToEnvironment = tl.getBoolInput("addSpnToEnvironment", false);
this.useWithoutJSON = tl.getBoolInput("useWithoutJSON", false);

return this;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DeploymentScopeBase {
setVariablesInObject(`${path}.${key}`, obj[key]);
}
else {
console.log(`##vso[task.setvariable variable=${path}.${key};]` + JSON.stringify(obj[key]));
console.log(`##vso[task.setvariable variable=${path}.${key};]` + (this.taskParameters.useWithoutJSON ? obj[key] : JSON.stringify(obj[key])));
console.log(tl.loc("AddedOutputVariable", `${path}.${key}`));
}
}
Expand Down
13 changes: 11 additions & 2 deletions Tasks/AzureResourceManagerTemplateDeploymentV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 223,
"Patch": 1
"Minor": 224,
"Patch": 0
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -225,6 +225,15 @@
"required": false,
"helpMarkDown": "Adds service principal id and key of the Azure endpoint you chose to the script's execution environment. You can use these variables: `$servicePrincipalId` and `$servicePrincipalKey` in your override parameters like `-key $servicePrincipalKey`",
"groupName": "Advanced"
},
{
"name": "useWithoutJSON",
"type": "boolean",
"label": "Use individual output values without JSON.Stringify applied",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Individual output values are being converted via JSON.Stringify by default. If you want to use the output values as it is without converting them via JSON.Stringify, enable this option. For more details refer to [this](https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceManagerTemplateDeploymentV3#deployment-outputs)",
"groupName": "Advanced"
}
],
"dataSourceBindings": [
Expand Down
13 changes: 11 additions & 2 deletions Tasks/AzureResourceManagerTemplateDeploymentV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 223,
"Patch": 1
"Minor": 224,
"Patch": 0
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -225,6 +225,15 @@
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.addSpnToEnvironment",
"groupName": "Advanced"
},
{
"name": "useWithoutJSON",
"type": "boolean",
"label": "ms-resource:loc.input.label.useWithoutJSON",
"defaultValue": "false",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.useWithoutJSON",
"groupName": "Advanced"
}
],
"dataSourceBindings": [
Expand Down