Home > Back-end >  How to get verbose output from custom powershell extension in Azure Devops
How to get verbose output from custom powershell extension in Azure Devops

Time:10-14

I have a custom extension for Azure Devops built in powershell. It works fine, however I'd like to get verbose output in logs from New-AzResourceGroupDeployment. No matter what I try - the output is hidden:

-Verbose with default $verbosePreference
-Verbose with $verbosePreference = "Continue"
-Verbose 4>&1 with default $verbosePreference
-Verbose 4>&1 with $verbosePreference = "Continue"

Locally it works fine. Any pointers?
ps. can't share extension code, unfortunately, but the relevant part is this:

$templateParameters = @{
    Verbose = $true
    xxx
}
New-AzResourceGroupDeployment -ResourceGroup $rg @TemplateParameters 4>&1

EDIT: from what I can understand https://github.com/microsoft/azure-pipelines-task-lib/tree/master/powershell this library is rerouting the output. that can be reproduced locally with (after you import the library):

Invoke-VstsTastScript -ScriptBlock { Invoke-RestMethod -Method:post 'postman-echo.com/post' -Body 'test' -UseBasicParsing -Verbose }

CodePudding user response:

Unfortunately, I am unable to comment but wanted to suggest the use of Out-String.

$templateParameters = @{
    ResourceGroup = $rg
    Verbose = $true
}
New-AzResourceGroupDeployment @TemplateParameters 4>&1 | Out-String

What you're not showing is the actual output to the logs which could be the culprit.

  • Related