0
  $FX_USER=$args[0]
  $FX_PWD=$args[1]
  $FX_JOBID=$args[2]
  $REGION=$args[3]
  $TAGS=$args[4]
  $SUITES=$args[5]
  $CATEGORIES=$args[6]
  $FX_HOST=$args[7]      

  $taskStatus="WAITING"
  Write-Host "taskStatus = " $taskStatus


 while ( ("$taskStatus" -eq "WAITING") -or ("$taskStatus" -eq "PROCESSING") ) 
           { 
    sleep 5
     Write-Host "Checking Status...."

             $passPercent=$(curl -k --header "Content-Type: application/json;charset=UTF-8" -X GET -u ""${FX_USER}":"${FX_PWD}"" ""${FX_HOST}"/api/v1/runs/${runId}" | jq -r '."data"|.ciCdStatus')


              $array =  $passPercent  | ConvertFrom-Json 

        $taskStatus="${array[0]}"
             Write-Host "task-status= $taskStatus"
             Write-Host "Status =" "${array[0]}" " Success Percent =" "${array[1]}"  " Total Tests =" "${array[2]}" " Time Taken =" "${array[4]}" " Run =" "${array[5]}"    

when i run this code of powershell i got following error from console output.

ConvertFrom-Json : Invalid JSON primitive: WAITING. At C:\Users\Administrator\test.ps1:57 char:45 + $array = $passPercent | ConvertFrom-Json + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

Status = Success Percent = Total Tests = Time Taken = Run =

I am supposed to get some values either in string or interger after = sign in above fields like Status= Completed, Can anyone help me out its urgent. Thanks

  • 1
    nvm, it appears you’re using jq to deal with the JSON. So before using ConvertFrom-Json you should check if $passPercent even contains JSON. – Daniel B Mar 31 at 10:23
  • this is what is store in passPercent after curl passPercent=WAITING:0.0:0:0:null:null:38:/#/app/projects/8a80808a69c899f10169c8a0d0610005/jobs/8a80808a69c899f10169c8a0da020079/runs/8a8080f169d28d430169d35e399401f8:Bugs Logged = 0 Bugs Reopened = 0 Bugs Closed = 0 Total Bugs = 0 – James Taylor Mar 31 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.