Reputation: 574
There are a few related questions in stack I'll drop them below. I'm working with Azure DevOps api 5.1 and attempting to queue a build.
{
"Definition": {
"id": "7"
}
}
This will queue a build with the variables that are already set in the definition. I have attempted to pass in variables in a few different ways both of which wound up not being honored by the API at all.
{
"Definition": {
"id": "7",
"variables": {
"tag": "@{value=v1.1.0}",
"system.debug": "@{value=true}"
}
}
}
Per some of the related questions I also attempted
{
"Definition": {
"id": "7",
"parameters": {
"tag": "@{value=v1.1.0}",
"system.debug": "@{value=true}"
}
}
}
After capturing the output from chrome while queuing a build via the UI it appears to expect variables as opposed to parameters, but what i'm seeing when i go back to view the builds is that the variables being passed in are not being honored. Additionally I have taken the definition I wish to run and stashed it into the body.definition above.
VSTS use API to set build parameters at queue time
TFS 2017 API; Queuing a build with variables
How to QUEUE a new build using VSTS REST API
Please let me know if I should add more detail I've not put the actual code, but it is pretty straightforward
Invoke-RestMethod -Method post -Uri $uri -Headers $Header -ContentType 'application/json' -Body ($Body |ConvertTo-Json -Compress -Depth 10)
Upvotes: 2
Views: 1595
Reputation: 21
In case anyone runs across this in the future: I got this working via the "queue build" REST call: https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-server-rest-6.0
Upvotes: 0
Reputation: 48
There is also the Run Pipeline rest api available:
pipelineId in url is definitionId
{
"templateParameters": {
"param1": "paramValue1",
"param2": "paramValue2",
"param3": "paramValue3"
}
}
Documented here.
Not enough rep to comment
Upvotes: 3
Reputation: 574
After firing up postman and finding a collection it appears there were two issues with how I was attempting to pass the variables.
Problem 1: variables vs parameters
Even though based on several questions here as well as capturing the traffic from web browser to devops. You cannot use variables as a part of the definition, it must be parameters. Additionally it appears that they cannot be nested inside the definition (body.definition.parameters) they must be at the same level as defintions (body.parameters).
Problem 2: format
The parameters value must be compressed json, additionally it cannot be an object, it must be variable:value.
{
"definition": {
"id": 7
},
"parameters": "{\"tag\":\"v3.2.1\"},\"system.debug\":\"true\"}"
}
I feel I've seen this answer before possibly in one of the related questions I posted above. Apologies for all the duplication of effort.
Upvotes: 1