Search code examples
c#azureazure-devopsazure-devops-rest-apitfs-sdk

VSTS Update build via REST API


My goal is to update the build's pool information to move the queued build/build into another pool via the REST API. I have tried a lot of things and cannot find any documentation - not even on which parameters can actually be set

Code I have tried to accomplish this task with:

try
{
    build.Queue.Id = newQueue.Id;
    build.Queue.Name = newQueue.Name;
    build.Queue.Pool = new Microsoft.TeamFoundation.Build.WebApi.TaskAgentPoolReference();
    build.Queue.Pool.Name = newQueue.Pool.Name;
    build.Queue.Pool.Id = newQueue.Pool.Id;
    build.Queue.Pool.IsHosted = newQueue.Pool.IsHosted;
    var c = connection.GetBuildClient();
    var tf = await  c.UpdateBuildAsync(build);

    return true;
}
catch (Exception ex)
{
    return false;
}

(the above code is very hacky as I am attempting to make it work)


Things I have tried:

1) I have tried copying the exact json and sending it via a raw patch request, then I get a response saying that it is modified. But NOTHING is modified except the last modified user changing to me

2) I have tried editing the AgentsPoolQueue in the request body via the API, but it is not the pool I want to change - but the Build's pool information to link to another build instead.


Solution

  • update the build's pool information to move the queued build/build into another pool via the REST API

    After testing, updating the queued build's agent pool through the rest API is currently not supported in Azure Devops . Once build is run, its agent pool information cannot be modified.

    Although the AgentPoolQueue is recorded in the request body in the Update-build rest api document. However, when you actually use it, you will find that the return status is 200 ok, but the pool information in the build has not actually been updated. This is not stated in the documentation and it does cause confusion.

    The agent pool is determined when you run pipeline. Once the build is running, even in the queue state, it cannot be changed. You could submit your request for this feature on our UserVoice site, which is our main forum for product suggestions. More votes and comments can increase the priority of feedback.

    At present, you can only cancel the queued builds, run new builds, and re-specify the agent pool in the new builds.