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 debug flag to arm deployment command #1188

Merged
2 commits merged into from
Nov 11, 2020
Merged
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
12 changes: 10 additions & 2 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ if ($CI) {
if ($EnvironmentVariables.ContainsKey('AZURE_RESOURCEGROUP_NAME') -and `
$EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'] -ne $ResourceGroupName)
{
Write-Warning ("Overwriting 'EnvironmentVariables.AZURE_RESOURCEGROUP_NAME' with value " +
Write-Warning ("Overwriting 'EnvironmentVariables.AZURE_RESOURCEGROUP_NAME' with value " +
"'$($EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'])' " + "to new value '$($ResourceGroupName)'")
}
$EnvironmentVariables['AZURE_RESOURCEGROUP_NAME'] = $ResourceGroupName
Expand Down Expand Up @@ -385,7 +385,15 @@ foreach ($templateFile in $templateFiles) {

Log "Deploying template '$templateFile' to resource group '$($resourceGroup.ResourceGroupName)'"
$deployment = Retry {
New-AzResourceGroupDeployment -Name $BaseName -ResourceGroupName $resourceGroup.ResourceGroupName -TemplateFile $templateFile -TemplateParameterObject $templateFileParameters
$lastDebugPreference = $DebugPreference
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you simply pass -Debug do this cmdlet? Doesn't that equate to the same thing without the need for the try/finally block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing, adding -Debug sets $DebugPreference to "Inquire" for the rest of the script context. This does two undesired things: we don't want debug output for the rest of the script, and the Inquire setting requires manual confirmation, as opposed to "Continue".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.1#debug

That seems to suggest that it will set it to Continue in non-interactive mode. I'm not even sure what Inquire does.

It seems weird that it isn't scoped to just the one cmdlet call but if that is the case what you have works.

if ($CI) {
$DebugPreference = "Continue"
}
New-AzResourceGroupDeployment -Name $BaseName -ResourceGroupName $resourceGroup.ResourceGroupName -TemplateFile $templateFile -TemplateParameterObject $templateFileParameters
} finally {
$DebugPreference = $lastDebugPreference
}
}

if ($deployment.ProvisioningState -eq 'Succeeded') {
Expand Down