Visual Studio Team Services has an API, so we can queue and cancel build via API.
Here is an API about the build.
Microsoft provides four NuGet libraries for VSTS API.
Microsoft.TeamFoundationServer.Client is the library to execute build operation. However, it's hard to use. I write sample codes for queuing and cancelling build.
Here is a sample.
QueueBuildAsync, which is a method to queue a build, has the
Build object as a parameter.
Build object has many properties. However, there is no document which property is required. I found
Definition.Id (id of build definition) and
Project property are necessary after several tries.
Next, I'd like to cancel the queued build from C# code. What do I do? There is no API in the list. "Delete" method is not the API for cancelling but for deleting the completed build itself.
The answer is executing "update" method. We should update the queued build status to "cancel".
We should execute two or more API calls to queue or cancel build. That's the way to execute them from C# code.