admin管理员组文章数量:1124387
I have an Azure PowerShell task in an Azure DevOps Pipeline that creates Web Apps by deploying an ARM Template.
I'm trying to deploy a Web App with the specific environment variables and while they work fine when I define the variables in the YAML, they are not being passed when I define the Environment Variables via Variable Groups.
This is the task that works fine:
- checkout: self
- task: AzurePowerShell@5
displayName: "Create Web Apps"
inputs:
azureSubscription: 'XXX'
ScriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
errorActionPreference: 'silentlyContinue'
Inline: |
# Define variables
$ARMTemplateFile = "$(Build.Repository.LocalPath)\ARM-Templates\WebApps.json"
$ResourceGroupName = "XXX"
$WebAppEnvironmentVariables = @{
"Name1" = "Value1"
"Name2" = "Value2"
}
# Use Azure PowerShell to deploy the ARM template
New-AzResourceGroupDeployment `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $ARMTemplateFile `
-TemplateParameterObject @{
"EnvironmentVariables" = $WebAppEnvironmentVariables
}
I've tried every possible combination that I could think of and none of them work when referencing object from the Variable Groups. The template gets deployed, but the Environment Variables are empty:
- checkout: self
- task: AzurePowerShell@5
displayName: "Create Web Apps"
inputs:
azureSubscription: 'XXX'
ScriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
pwsh: true
Inline: |
# Define variables
$ARMTemplateFile = "$(Build.Repository.LocalPath)\ARM-Templates\WebApps.json"
$ResourceGroupName = "XXX"
# Use Azure PowerShell to deploy the ARM template
New-AzResourceGroupDeployment `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $ARMTemplateFile `
-TemplateParameterObject @{
"EnvironmentVariables" = $(VariablesObject1)
}
I have an Azure PowerShell task in an Azure DevOps Pipeline that creates Web Apps by deploying an ARM Template.
I'm trying to deploy a Web App with the specific environment variables and while they work fine when I define the variables in the YAML, they are not being passed when I define the Environment Variables via Variable Groups.
This is the task that works fine:
- checkout: self
- task: AzurePowerShell@5
displayName: "Create Web Apps"
inputs:
azureSubscription: 'XXX'
ScriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
errorActionPreference: 'silentlyContinue'
Inline: |
# Define variables
$ARMTemplateFile = "$(Build.Repository.LocalPath)\ARM-Templates\WebApps.json"
$ResourceGroupName = "XXX"
$WebAppEnvironmentVariables = @{
"Name1" = "Value1"
"Name2" = "Value2"
}
# Use Azure PowerShell to deploy the ARM template
New-AzResourceGroupDeployment `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $ARMTemplateFile `
-TemplateParameterObject @{
"EnvironmentVariables" = $WebAppEnvironmentVariables
}
I've tried every possible combination that I could think of and none of them work when referencing object from the Variable Groups. The template gets deployed, but the Environment Variables are empty:
- checkout: self
- task: AzurePowerShell@5
displayName: "Create Web Apps"
inputs:
azureSubscription: 'XXX'
ScriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
pwsh: true
Inline: |
# Define variables
$ARMTemplateFile = "$(Build.Repository.LocalPath)\ARM-Templates\WebApps.json"
$ResourceGroupName = "XXX"
# Use Azure PowerShell to deploy the ARM template
New-AzResourceGroupDeployment `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $ARMTemplateFile `
-TemplateParameterObject @{
"EnvironmentVariables" = $(VariablesObject1)
}
Share
Improve this question
edited yesterday
bryanbcook
17.6k2 gold badges44 silver badges73 bronze badges
asked 2 days ago
WinBossWinBoss
9231 gold badge23 silver badges49 bronze badges
6
|
Show 1 more comment
1 Answer
Reset to default 1According to New-AzResourceGroupDeployment's documentation, -TemplateParameterObject
must be an Hashtable
:
New-AzResourceGroupDeployment
# ...
-TemplateParameterObject <Hashtable>
So instead of:
- task: AzurePowerShell@5
displayName: "Create Web Apps"
inputs:
azureSubscription: 'XXX'
ScriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
pwsh: true
Inline: |
# Define variables
$ARMTemplateFile = "$(Build.Repository.LocalPath)\ARM-Templates\WebApps.json"
$ResourceGroupName = "XXX"
# Use Azure PowerShell to deploy the ARM template
New-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
-TemplateFile $ARMTemplateFile `
-TemplateParameterObject @{
"EnvironmentVariables" = $(VariablesObject1)
}
Try converting the JSON string to a hashtable:
- task: AzurePowerShell@5
displayName: "Create Web Apps"
inputs:
azureSubscription: 'XXX'
ScriptType: 'InlineScript'
azurePowerShellVersion: 'LatestVersion'
errorActionPreference: 'silentlyContinue'
Inline: |
# Define variables
$ARMTemplateFile = "$(Build.Repository.LocalPath)\ARM-Templates\WebApps.json"
$ResourceGroupName = "XXX"
$WebAppEnvironmentVariables = $env:MyVariables | ConvertFrom-Json -AsHashtable
# Use Azure PowerShell to deploy the ARM template
New-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
-TemplateFile $ARMTemplateFile `
-TemplateParameterObject @{
"EnvironmentVariables" = $WebAppEnvironmentVariables
}
env:
MyVariables: $(VariablesObject1) # <-------------------- from variable group
Note: I'm setting a task-level environment variable to avoid escaping issues.
本文标签: azure devopsPass PowerShell Object from Variable GroupStack Overflow
版权声明:本文标题:azure devops - Pass PowerShell Object from Variable Group - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736620356a1945561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
VariablesObject1
variable? Is that variable suppose to contain a json string like in the first code block? – Rui Jarimba Commented 2 days ago$(VariablesObject1)
is set when running theAzurePowerShell@5
task? If you add a dummy task to print that variable value is displayed correctly? – Rui Jarimba Commented yesterdayWrite-Host '(VariablesObject1)'
– WinBoss Commented yesterdayNew-AzResourceGroupDeployment
invocation? e.g. use$WebAppEnvironmentVariables = $(VariablesObject1)
followed byNew-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName ... -TemplateParameterObject @{ "EnvironmentVariables" = $WebAppEnvironmentVariables }
– Jonathan Dodds Commented yesterday