Azure / AzOps

AzOps is a PowerShell module which deploys (Push) ARM Resource Templates & Bicep files at all Azure scope levels and exports (Pull) ARM resource hierarchy.
https://aka.ms/AzOps
MIT License
371 stars 158 forks source link

WhatIf report fails with Cannot bind argument to parameter 'FilePath' because it is null #853

Closed bjompen closed 5 months ago

bjompen commented 5 months ago

Describe the bug

Verify and create feedback / WhatIf report fails with Cannot bind argument to parameter 'FilePath' because it is null See image 1 for error, Error 2 for context.

In certain scenarios it appears that WhatIf fails as above. Setting message.info.maximum = 9 and enabling system.debug in Azure DevOps to get all messages let us track the error down to the following scenario:

We are running a serial deploy (Image 3) so in Invoke-AzOpsPush we are either in line 497, line 508 or line 513

Inside New-AzOpsDeployment in out scenario we are running a bicep/json file the scope set is resource group and we end up inside this if statement

Here we run Set-AzOpsContext which is a wrapper around Set-AzContext

The issue now is that Set-AzContext outputs the result of the context switch, and back in the calling script, Invoke-AzOpsPush, the output from Set-AzContext is caught in the $DeploymentResult variable.

In line 518 we output $DeploymentResult to log as can be seen in image 2, and it now contains two objects:

The foreach loop following the output fails because the first object is a context object thatm logically enough, doesn't have a $_.filePath property.

Steps to reproduce

Run a verify pipeline with a bicep file? I honestly don`t know if it hits every time, or only when you have to change context.

Extra stuff

I can of course share complete logs, but since they contain sensitive data we can take that in private if needed.

Proposed solution would be to simply change lines 103 and 112 in New-AzOpsDeployment to $null = Set-AzOpsContext -ScopeObject $scopeObject instead and simply ignore any output from it. Let me know if this is good and I'll fix it right away.

Screenshots

Image 1: image

Image 2: image

Image 3: image

bjompen commented 5 months ago

Added suggested solution to referenced PR #854

Jefajers commented 5 months ago

Hi @bjompen, I can reproduce the scenario quite frequently 👍 .

Thanks for a great and through report and suggesting a fix 🥇 .