1

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)
Jeff Patton
  • 551
  • 4
  • 15
  • I should add that the build I'm running is a simple powershell script that kicks out the tag variable for confirmation, and I'm not seeing the value I pass in. – Jeff Patton Apr 15 '20 at 17:43
  • Also just noticed the code rendered above has @'s i think that is a stack formatting thing, as there are no @'s in the code as run. – Jeff Patton Apr 15 '20 at 18:10

3 Answers3

2

There is also the Run Pipeline rest api available:

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

pipelineId in url is definitionId

{
  "templateParameters": {
    "param1": "paramValue1",
    "param2": "paramValue2",
    "param3": "paramValue3"
  }
}

Documented here.

Not enough rep to comment

1

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.

Jeff Patton
  • 551
  • 4
  • 15
  • Glad you fixed the issue, Please let me know if I can assist with anything else – Amit Baranes Apr 15 '20 at 19:49
  • Much appreciate this solution shared here. It would much better if you can accept this answer, then other SO users could direct know this is a correct solution. – Mengdi Liang Apr 19 '20 at 12:11
0

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

Bosch-Eli
  • 11
  • 1
  • 1
  • 3