简体   繁体   中英

create iteration with child nodes in Azure DevOps (VSTS) using c#

I am writing a program that would create iteration with its child nodes. It creates a parent node but none of the child nodes. Below is my sample code.

I took help from the link: https://github.com/microsoft/azure-devops-dotnet-samples/blob/master/ClientLibrary/Samples/WorkItemTracking/ClassificationNodesSample.cs

WorkItemClassificationNode iterationNode = new WorkItemClassificationNode()
{
    Name = "Parent Iteration",
    StructureType = TreeNodeStructureType.Iteration,
    Children = new List<WorkItemClassificationNode>()
    {
        new WorkItemClassificationNode(){ Name="child 1", StructureType= TreeNodeStructureType.Iteration },
        new WorkItemClassificationNode(){ Name="child 2", StructureType= TreeNodeStructureType.Iteration },
    },
    Attributes = new Dictionary<string, Object>()
    {
        { "startDate", DateTime.Today },
        { "finishDate", DateTime.Today.AddDays(7) },
    }

};
witClient.CreateOrUpdateClassificationNodeAsync(iterationNode, Constants.TEAM_PROJECT, TreeStructureGroup.Iterations);

I could only create "Parent Iteration". Need to create it like: "Parent Iteration\\Child 1" and "Parent Iteration\\Child 2"

You have to create each iteration (first parent then child). This is my function to create iteration:

    static WorkItemClassificationNode CreateIteration(string TeamProjectName, string IterationName, DateTime? StartDate = null, DateTime? FinishDate = null, string ParentIterationPath = null)
    {
        WorkItemClassificationNode newIteration = new WorkItemClassificationNode();
        newIteration.Name = IterationName;

        if (StartDate != null && FinishDate != null)
        {
            newIteration.Attributes = new Dictionary<string, object>();
            newIteration.Attributes.Add("startDate", StartDate);
            newIteration.Attributes.Add("finishDate", FinishDate);
        }

        return WitClient.CreateOrUpdateClassificationNodeAsync(newIteration, TeamProjectName, TreeStructureGroup.Iterations, ParentIterationPath).Result;
    }

var newNode = CreateIteration(TeamProjectName, @"R2");
newNode = CreateIteration(TeamProjectName, @"R2.1", ParentIterationPath: @"R2");
newNode = CreateIteration(TeamProjectName, @"Ver1", new DateTime(2019, 1, 1), new DateTime(2019, 1, 7), @"R2\R2.1");

The example of using is here: https://github.com/ashamrai/TFRestApi/blob/master/08.TFRestApiAppAreasAndIterations/TFRestApiApp/Program.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM