Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.VisualStudio.Services.Common;
class Program
{
static void Main(string[] args)
{
QueueBuild("https://<yourdomain>.VisualStudio.com/DefaultCollection/", "<username>", "<password>", "<project>", "<BuildDefinitionname>").GetAwaiter().GetResult();
Console.ReadLine();
}
static async Task QueueBuild(string url, string userName, string password, string project, string buildDefinitionName)
{
var build = new BuildHttpClient(new Uri(url), new VssBasicCredential(userName, password));
// First we get project's GUID and buildDefinition's ID.
// Get the list of build definitions.
var definitions = await build.GetDefinitionsAsync(project: project);
// Get the specified name of build definition.
var target = definitions.First(d => d.Name == buildDefinitionName);
// Build class has many properties, hoqever we can set only these properties.
//ref: https://www.visualstudio.com/integrate/api/build/builds#queueabuild
//In this nuget librari, we should set Project property.
//It requires project's GUID, so we're compelled to get GUID by API.
var res = await build.QueueBuildAsync(new Build
{
Definition = new DefinitionReference
{
Id = target.Id
},
Project = target.Project
});
Console.WriteLine($"Queued build with id: {res.Id}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.