Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTS use API to set build parameters at queue time

I need to queue a VSTS build from the REST API Documented at https://docs.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?

like image 583
leemicw Avatar asked Jun 13 '18 13:06

leemicw


1 Answers

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\"}"

}

like image 130
jessehouwing Avatar answered Nov 15 '22 06:11

jessehouwing