Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get build definitions from TFS?

Tags:

c#

tfs

alm

How to get build definitions using TFS-API given collection-guid and project-name

Please refer here for more details. This is one of the best resources on TFS stuff.

like image 388
Martin Avatar asked Apr 19 '13 10:04

Martin


1 Answers

private TfsConfigurationServer configurationServer;  

configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(uri);



public IList<KeyValuePair<string, Uri>> GetBuildDefinitionListFromProject(Guid collectionId, string projectName)
{
    List<IBuildDefinition> buildDefinitionList = null;
    List<KeyValuePair<string, Uri>> buildDefinitionInfoList = null;

    try
    {
        buildDefinitionInfoList = new List<KeyValuePair<string, Uri>>();
        TfsTeamProjectCollection tfsProjectCollection =
        configurationServer.GetTeamProjectCollection(collectionId);
        tfsProjectCollection.Authenticate();
        var buildServer = (IBuildServer)tfsProjectCollection.GetService(typeof(IBuildServer));
        buildDefinitionList = new List<IBuildDefinition>(buildServer.QueryBuildDefinitions(projectName));
    }
    catch (Exception e)
    {
        ApplicationLogger.Log(e);
    }

    if (buildDefinitionList != null && buildDefinitionList.Count > 0)
    {
        foreach (IBuildDefinition builddef in buildDefinitionList)
        {
            buildDefinitionInfoList.Add(new KeyValuePair<string, Uri>(builddef.Name, builddef.Uri));
        }
    }
    return buildDefinitionInfoList;
}
like image 163
Martin Avatar answered Sep 21 '22 16:09

Martin