Off the top of my head, I'd guess that the quoting is wrong in your JSON.
You're using things like "$token, $base64, etc. and those are being seen as variable names in the JSON and are being interpolated. I'd guess that the intention is to pass the "$token" (for example) as a string and not the value of the unassigned variable named $token.
If I remove the trailing comma from the line '"throw Quality gate failed"' and then feed the JSON into ConvertFrom-JSON I get this:
PS C:\Users\richm> $y.inputs.script
= [System.Text.Encoding]::UTF8.GetBytes( + ":"),
= [System.Convert]::ToBase64String(),
= [string]::Format("Basic {0}", ),
= @{Authorization = },
= Invoke-RestMethod -Method Get -Uri "http://xxx/api/project_badges/measure?project=myrepo&metric=alert_status" -Headers
| ConvertTo-Json | Write-Host
if (.projectStatus.status -eq "OK")
Write-Host "Quality Gate Succeeded"
else
throw "Quality gate failed"
There are no "left side" to the assignments!
Try escaping the "$" characters like this "`$token".