Let's say that we have an Azure pipeline task like so:
# Azure resource group deployment v2
# Deploy an Azure Resource Manager (ARM) template to a resource group and manage virtual machines.
- task: AzureResourceGroupDeployment@2
inputs:
azureSubscription: someSubscription
action: someAction
resourceGroupName: someResourceGroupName
templateLocation: someTemplateLocation
deploymentMode: someDeploymentmode
overrideParameters: '
-parameter1 "value1"
-parameter2 "value1"
This task will deploy some ARM template with two overridedParameters.
My question is, is it possible to add a condition inside the "overrideParameters" to avoid passing "parameter2" depending on the situation? (Assuming of course that those parameters are optional in the ARM)
Example of what I would like in pseudo-code:
# Azure resource group deployment v2
# Deploy an Azure Resource Manager (ARM) template to a resource group and manage virtual machines.
- task: AzureResourceGroupDeployment@2
inputs:
azureSubscription: someSubscription
action: someAction
resourceGroupName: someResourceGroupName
templateLocation: someTemplateLocation
deploymentMode: someDeploymentmode
overrideParameters: '
-parameter1 "value1"
if(someVariableisTrue):
-parameter2 "value1"
I've tried similar approaches but I couldn't make it work, there are less elegant ways like creating a conditional task or even adding a condition that controls the overrideParameters like this:
# Azure resource group deployment v2
# Deploy an Azure Resource Manager (ARM) template to a resource group and manage virtual machines.
- task: AzureResourceGroupDeployment@2
inputs:
azureSubscription: someSubscription
action: someAction
resourceGroupName: someResourceGroupName
templateLocation: someTemplateLocation
deploymentMode: someDeploymentmode
${{if someVariableisTrue}}:
overrideParameters: '
-parameter1 "value1"
-parameter2 "value1"
'
${{else}}:
overrideParameters: '
-parameter1 "value1"
'
But I would like to avoid that if there is a better solution.
Thanks in advance!
Edit
To avoid confusion what I really wold love would be this:
# Azure resource group deployment v2
# Deploy an Azure Resource Manager (ARM) template to a resource group and manage virtual machines.
- task: AzureResourceGroupDeployment@2
inputs:
azureSubscription: someSubscription
action: someAction
resourceGroupName: someResourceGroupName
templateLocation: someTemplateLocation
deploymentMode: someDeploymentmode
overrideParameters: '
-parameter1 "value1"
${{ if ne(value, '')}}: ###Just example condition could be anything
-parameter2 "value1"
The purpose of that is so we can achieve a code with high maintainability, so if now another person wants to add another optional parameter doesn't need to copy code and create a "monstruous" condition, that person will just need to add another if.
To clarify further, if I try something like the code above I get this;
The directive 'if' is not allowed in this context. Directives are not supported for expressions that are embedded within a string. Directives are only supported when the entire value is an expression.