Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

rest - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...