Skip to content

Instantly share code, notes, and snippets.

Last active February 21, 2016 08:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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>", "<username>", "<password>", "<project>", "<BuildDefinitionname>").GetAwaiter().GetResult();
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.
//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