arm-ttk-extension icon indicating copy to clipboard operation
arm-ttk-extension copied to clipboard

[error]You cannot call a method on a null-valued expression.

Open paul-haigh opened this issue 4 years ago • 8 comments

Trying to run ARM-TTK on our entire repo, which has files in lots of folders. Most recent run with no '*' in the folder source, nets this output:

##[debug]Importing function 'Test-FolderContents'.
##[debug]INPUT_TEMPLATELOCATION: 'D:\a\1\s\ARM\'
##[debug]INPUT_RESULTLOCATION: 'D:\a\1\s'
##[debug]INPUT_INCLUDETESTS (empty)
##[debug]INPUT_SKIPTESTS (empty)
##[debug]Caught exception from task script.
##[debug]Error record:
##[debug]D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\arm-ttk\testcases\deploymentTemplate\Location-Should-Not-Be-Hardcoded.test.ps1 : You cannot call a method on a null-valued expression.
##[debug]At D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\arm-ttk\Test-AzTemplate.ps1:201 char:21
##[debug]+                     & $TheTest @testInput 2>&1 3>&1
##[debug]+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[debug]    + CategoryInfo          : InvalidOperation: (:) [Location-Should...dcoded.test.ps1], RuntimeException
##[debug]    + FullyQualifiedErrorId : InvokeMethodOnNull,Location-Should-Not-Be-Hardcoded.test.ps1
##[debug] 
##[debug]Script stack trace:
##[debug]at <ScriptBlock>, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\arm-ttk\testcases\deploymentTemplate\Location-Should-Not-Be-Hardcoded.test.ps1: line 17
##[debug]at Test-Case, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\arm-ttk\Test-AzTemplate.ps1: line 201
##[debug]at Test-Group, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\arm-ttk\Test-AzTemplate.ps1: line 226
##[debug]at Test-FileList, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\arm-ttk\Test-AzTemplate.ps1: line 346
##[debug]at Test-AzTemplate<End>, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\arm-ttk\Test-AzTemplate.ps1: line 489
##[debug]at Test-FolderContents, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\invoke-ttk.psm1: line 12
##[debug]at Invoke-TTK, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\invoke-ttk.psm1: line 71
##[debug]at <ScriptBlock>, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.9\powershell.ps1: line 28
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]at <ScriptBlock>, <No file>: line 22
##[debug]at <ScriptBlock>, <No file>: line 18
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
##[debug]   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
##[debug]   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
##[debug]   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
##[debug]   at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
##[debug]   at System.Management.Automation.CommandProcessorBase.Complete()
##[error]You cannot call a method on a null-valued expression.
##[debug]Processed: ##vso[task.logissue type=error]You cannot call a method on a null-valued expression.
##[debug]Processed: ##vso[task.complete result=Failed]
Finishing: Run Azure RM TTK Tests

paul-haigh avatar Oct 13 '20 12:10 paul-haigh

I think this is down to a change I made at the weekend that has now been rolled back, if you wait for your extension to get updated to 1.0.10 and try again and see if that works.

sam-cogan avatar Oct 13 '20 19:10 sam-cogan

I've pushed a new version with fixes now, can you try this again please?

sam-cogan avatar Oct 14 '20 16:10 sam-cogan

Sorry to say, still getting the same with 1.0.11


##[debug]Importing alias 'Sort-AzTemplate'.
##[debug]Importing alias 'Test-AzureRMTemplate'.
##[debug]Loading module from path 'D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\Export-NUnitXml.psm1'.
##[debug]Exporting function 'Export-NUnitXml'.
##[debug]Importing function 'Export-NUnitXml'.
##[debug]Loading module from path 'D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\invoke-ttk.psm1'.
##[debug]Exporting function 'Test-FolderContents'.
##[debug]Exporting function 'Invoke-TTK'.
##[debug]Importing function 'Invoke-TTK'.
##[debug]Importing function 'Test-FolderContents'.
##[debug]INPUT_TEMPLATELOCATION: 'D:\a\1\s\ARM\*'
##[debug]INPUT_RESULTLOCATION: 'D:\a\1\s'
##[debug]INPUT_INCLUDETESTS (empty)
##[debug]INPUT_SKIPTESTS (empty)
##[debug]Caught exception from task script.
##[debug]Error record:
##[debug]D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\testcases\deploymentTemplate\Location-Should-Not-Be-Hardcoded.test.ps1 : You cannot call a method on a null-valued expression.
##[debug]At D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\Test-AzTemplate.ps1:201 char:21
##[debug]+                     & $TheTest @testInput 2>&1 3>&1
##[debug]+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[debug]    + CategoryInfo          : InvalidOperation: (:) [Location-Should...dcoded.test.ps1], RuntimeException
##[debug]    + FullyQualifiedErrorId : InvokeMethodOnNull,Location-Should-Not-Be-Hardcoded.test.ps1
##[debug] 
##[debug]Script stack trace:
##[debug]at <ScriptBlock>, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\testcases\deploymentTemplate\Location-Should-Not-Be-Hardcoded.test.ps1: line 17
##[debug]at Test-Case, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\Test-AzTemplate.ps1: line 201
##[debug]at Test-Group, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\Test-AzTemplate.ps1: line 226
##[debug]at Test-FileList, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\Test-AzTemplate.ps1: line 346
##[debug]at Test-AzTemplate<End>, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\Test-AzTemplate.ps1: line 489
##[debug]at Test-FolderContents, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\invoke-ttk.psm1: line 12
##[debug]at Invoke-TTK, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\invoke-ttk.psm1: line 75
##[debug]at <ScriptBlock>, D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\powershell.ps1: line 28
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]at <ScriptBlock>, <No file>: line 22
##[debug]at <ScriptBlock>, <No file>: line 18
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
##[debug]   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
##[debug]   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
##[debug]   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
##[debug]   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
##[debug]   at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
##[debug]   at System.Management.Automation.CommandProcessorBase.Complete()
##[error]You cannot call a method on a null-valued expression.
##[debug]Processed: ##vso[task.logissue type=error]You cannot call a method on a null-valued expression.
##[debug]Processed: ##vso[task.complete result=Failed]
Finishing: Run Azure RM TTK Tests

paul-haigh avatar Oct 15 '20 12:10 paul-haigh

Top part of log (no idea why it's truncating it)

##[debug]Evaluating: succeeded()
##[debug]Evaluating succeeded:
##[debug]=> True
##[debug]Result: True
Starting: Run Azure RM TTK Tests
==============================================================================
Task         : Run Azure RM TTK Tests
Description  : Run Azure Resource Manager Template Test Kit Tests against ARM Templates
Version      : 1.0.11
Author       : Sam Cogan
Help         : [More Information](https://github.com/sam-cogan/arm-ttk-extension/blob/master/README.md)
==============================================================================
##[debug]VstsTaskSdk 0.11.0 commit 7ff27a3e0bdd6f7b06690ae5f5b63cb84d0f23f4
##[debug]Loading module from path 'D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\arm-ttk.psd1'.
##[debug]Loading 'FormatsToProcess' from path 'D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\arm-ttk.format.ps1xml'.
##[debug]Loading module from path 'D:\a\_tasks\RunARMTTKTests_2ca36c0f-3e63-493e-a71a-de798e634733\1.0.11\arm-ttk\arm-ttk.psm1'.
##[debug]Exporting function 'ConvertFrom-Json'.
##[debug]Exporting function 'Import-Json'.
##[debug]Exporting function 'Find-JsonContent'.
##[debug]Exporting function 'Expand-AzTemplate'.
##[debug]Exporting function 'Test-AzTemplate'.
##[debug]Exporting function 'Format-AzTemplate'.
##[debug]Exporting function 'Update-TTKCache'.
##[debug]Exporting alias 'Test-AzureRMTemplate'.
##[debug]Exporting alias 'Sort-AzTemplate'.

paul-haigh avatar Oct 15 '20 12:10 paul-haigh

Any chance I can get a copy of the template where this is happening? Removing anything sensitive. Plus details on how you have the extension setup in azure devops.

sam-cogan avatar Oct 15 '20 13:10 sam-cogan

Sam, it doesn't seem to pickup any templates - I was rather hoping it would find all of the .json files (there are>100 in the subfolders of the folder I'm pointing it to ARM/*, but there are no templates in that folder directly.

paul-haigh avatar Oct 15 '20 13:10 paul-haigh

ok, that was the issue the latest change was supposed to address, but your throwing a different error to others. Can you confirm what OS and PS version the agent you are running this in is? Also just to check, the path should be ARM* as these are windows paths.

sam-cogan avatar Oct 15 '20 14:10 sam-cogan

I'm using Windows 2019 from a DevOps pipeline agent (Hosted).

paul-haigh avatar Oct 20 '20 09:10 paul-haigh