Feb 22 2024
08:19 PM
- last edited on
Mar 05 2024
05:28 PM
by
TechCommunityAP
Feb 22 2024
08:19 PM
- last edited on
Mar 05 2024
05:28 PM
by
TechCommunityAP
Hi Team,
I am facing below error during build where I am using powershell to read json file contents
Error: A parameter cannot be found that matches parameter name 'Raw'
Details:
in Azure build pipeline I have added Powershell task of version 2.* and its type 'File Path'
I have provided argument to powershell as -path "System.DefaultWorkingDirectory\.......\*.json
-> In powershell file,
I have declared parameter as [string]$path
I have written instruction as below
$json = (Get-Content -Path $path -Raw) | ConvertFrom-Json
and facing the error as "Error: A parameter cannot be found that matches parameter name 'Raw'" during powershell execution.
I tried many things to sort this out. Can anyone suggest your views/suggestions on this issue.
May 06 2024 05:46 AM
hi@Satyam569,
1.while running the pipeline check the version of powershell, "Raw" parameter can be used for version3 ( https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?vie... ).
2.If in case powershell version is older then instead of Raw, you can use join or else update powershell version.
3. In my case what I did is as follows,
i) Instead of writing get content command in file, write a one more powershell@2 task , type of inline script .
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$FilePath = "path to file/jsoncontentfile.json" # Path
$figJson = (Get-Content $FilePath -Raw) | ConvertFrom-Json
name: 'ConvertJSON'
displayName: 'Convert Json '
ii) define the variables in above script from json>can pass variable between tasks in same job>so pass those as arguments for file type powershell@2 task, as already it is there. and remove the get content code from script.ps1 file.
I hope this is helpful 🙂