8

I need to queue a VSTS build from the REST API Documented at https://learn.microsoft.com/en-us/rest/api/vsts/build/builds/queue?view=vsts-rest-4.1

This answer helped me queue a basic build. I have been successful using a Personal Access Token (PAT) to authenticate and this json payload

{
    definition: {
        id: 19,
    }
}

I need to pass variables into the build as well. These are some of the things I have tried that are not working

Not working 1

{
    definition: {
        id: 19,
        variables: {
            "my.var.one": { allowOverride: true, isSecret: false, value: "stringvalue" },
            "my.var.two": { allowOverride: true, isSecret: false, value: "numberValue" }
        }
    }
}

Not working 2

{
    definition: {
        id: 19,
        variables: {
            "my.var.one": { value: "stringvalue" },
            "my.var.two": { value: "numberValue" }
        }
    }
}

Not working 3

{
    definition: {
        id: 19,
        variables: {
            "my.var.one": "stringvalue",
            "my.var.two": "numberValue"
        }
    }
}

It was suggested this question might have the answer since VSTS and TFS are similar. Unfortunately changing to the parameters variable and using the string representation of the object gives the same result. Removing the dots from the parameter names did not make a difference. Trying with the API Version 3.1 also got the same result.

Not working 4

{
    definition: {
        id: 19,
        parameters: '{
            "myVarOne": "stringValue",
            "myVarTwo": "numberValue"
        }'
    }
}

What is the correct way to format variables in the payload (or other location) to pass them to the build you are trying to queue?

leemicw
  • 751
  • 8
  • 15
  • 1
    Possible duplicate of [TFS 2017 API; Queuing a build with variables](https://stackoverflow.com/questions/50176797/tfs-2017-api-queuing-a-build-with-variables) – Daniel Mann Jun 13 '18 at 15:48

1 Answers1

15

Using the Chrome Developer tools to capture the payload of a Queue action in the web UI, I'd hazard a guess the format you're looking for is:

POST https://dev.azure.com/jessehouwing/6484ebc3-af16-4af9-aa66-6b3398db7214/_apis/build/builds
{
"queue": {
    "id": 27
},
"definition": {
    "id": 53
},
"project": {
    "id": "6484ebc3-af16-4af9-aa66-6b3398db7214"
},
"sourceBranch": "refs/heads/master",
"reason": 1,
"demands": [],
"parameters": "{\"system.debug\":\"true\",\"DefinedVariable\":\"Override Value\"}"

}

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thanks for the suggestion for watching the network window. I proposed an edit to the payload to show the minimum amount of payload to accomplish the task. If you don't approve, feel free to rollback. – leemicw Jun 14 '18 at 02:56
  • So what was the right way to pass your variables `myVarOne` etc? – Elliptica Sep 20 '19 at 05:41
  • 1
    `"parameters": "{\"system.debug\":\"true\", \"myVarOne\":\"something\"}` – jessehouwing Sep 21 '19 at 06:46
  • For future folks reaching this: note that the parameters value is a string in JSON format, not an array. – JohnTortugo Jan 25 '20 at 21:45
  • 1
    I have tried using parameters as suggested in this thread and the possible duplicate and neither are honoring the passed in parameters. – Jeff Patton Apr 15 '20 at 16:43
  • @JeffPatton, have you tried: Using the Chrome Developer tools to capture the payload of a Queue action in the web UI. – jessehouwing Oct 09 '20 at 10:23