0

I am able to kick off an Azure Devops Build job and send a text parameter but I only seem to be able to send a single parameter and not more. I need to send a token parameter Ok that works but I also want to send a text param that contains a json payload to be processed by a Powershell script in the Build job. So I have a Hellow World definition setup with two variables in Pipeline variables. First one is tokentext the second one is jsonInput. Both have the checkbox "Settable at queue time" checked. I have a PowerShell Inline script in the job definition with this:

Write-Host "Hello World"
Write-Host "tokentext: $(tokentext) `n"

Write-Host "Json Input"
Write-Host "---------------------------------------------------"
$(jsonInput)

My Body that I am sending to the Invoke-RestMethod is:

$body = @{ 
definition = @{
    id = $buildDefID
}    
parameters = "{`"tokentext`" :$mytoken}
              {`"jsonInput`" :$j}  
"
}
$b = $body  | ConvertTo-Json

This works but the above does not:

$body = @{ 
definition = @{
    id = $buildDefID
}    
parameters = "{`"tokentext`" :$mytoken}
"
}

$b = $body  | ConvertTo-Json

I have tried it with a comma separating the parameters etc.. All kids of things I have tried. I could sure use some assistance if anyone is sening multiple parameters to variables in a build Definition from a script.

Thanks

2 Answers 2

2

Below request body works for me. Please check it out.

$body = @{
  definition= @{id = $buildDefID};

  parameters ="{`"jsonInput`":`"$jsonInput`", `"tokentext`":`"$tokentext`"}"
 }
$b = $body  | ConvertTo-Json

You can also run your pipeline via Runs - Run Pipeline rest api which is less complicated.

POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.1-preview.1

pipelineId is the $buildDefID

You can put the parameters in your request body as below:

 $body=@{
     
     variables = @{
 
         jsonInput= @{value = $jsonInput};
     
         tokentext= @{value = $tokentext}
      }
  }

$b = $body  | ConvertTo-Json
Sign up to request clarification or add additional context in comments.

Comments

0

Please try this:

$body = @{ 
  definition = @{
    id = $buildDefID
  }    
  parameters = "{`"tokentext`" :$mytoken, `"jsonInput`" :$j}"
}
$b = $body  | ConvertTo-Json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.