Skip to content

Instantly share code, notes, and snippets.

@tanaka-takayoshi
Last active February 21, 2016 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanaka-takayoshi/60a71179998da8fe1588 to your computer and use it in GitHub Desktop.
Save tanaka-takayoshi/60a71179998da8fe1588 to your computer and use it in GitHub Desktop.
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