Hi
I am trying to trigger a build through the TFS API. First, I select the necessary changesets I want, then create a label for them, and then execute a selective build of these changesets. I get the following error message :
TFB210503: An error occurred while initializing a build for build definition \Test\Label Changesets: TF14064: Could not find label abel Demo@$/Test/BuildProcessTemplates/DefaultTemplate.xaml.
where the build definition name is "Label Changesets" and the Label name is "Demo".
Does this mean the label is not getting created successfully? If yes, please tell me how.
I am posting my codes below. Can someone tell me what's wrong??
Thanks, Tara.
/// <summary>
/// Performs the actual creation of the label for the selected changesets.
/// </summary>
/// <param name="selectedChangesets"></param>
/// <param name="selectedBuild"></param>
/// <param name="label"></param>
/// <param name="project"></param>
public void SetLabel(List selectedChangesets, string selectedBuild, string label, string project) { //Initializes a new label with a version number. LabelVersionSpec labelspec = new LabelVersionSpec(selectedBuild); // Get all items in the repository for the specified server path and label spec. ItemSet LabeledItems = tfvc.GetItems(@"$/" + project, labelspec, RecursionType.Full); // Create a array of items labeled with the selected build number. Item[] items = LabeledItems.Items;
List<int> changesetsInBuild = new List<int>();
// Add the changesets associated with the items.
AddNecessaryChangesets(selectedChangesets, items, changesetsInBuild);
VersionControlLabel labelToCreate;
List<LabelItemSpec> labelItemSpec;
//Initialize a representation of a version control label to be sent to the server.
CreateVersionControlLabel(label, project, out labelToCreate, out labelItemSpec);
// Actual creation of the label. Remove existing labels, if any.
try
{
LabelResult[] prevResults = tfvc.DeleteLabel(label, "$/" + project);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
LabelResult[] results = tfvc.CreateLabel(labelToCreate, labelItemSpec.ToArray(), LabelChildOption.Replace);
}
///
/// Initializes a label in version control.
/// </summary>
/// <param name="label">The user supplied label</param>
/// <param name="project">The team project name</param>
/// <param name="labelToCreate">The version control label</param>
/// <param name="labelItemSpec">A list of label items</param>
private void CreateVersionControlLabel(string label, string project, out VersionControlLabel labelToCreate, out List labelItemSpec) { labelToCreate = new VersionControlLabel(tfvc, label, tfvc.AuthenticatedUser, "$/" + project, "DemoLabel");
// Create Labeled Items and Remove items of build configuration files.
labelItemSpec = new List<LabelItemSpec>();
for (int i = 0; i < changeSets.Count; i++)
{
foreach (Change change in tfvc.GetChangeset(changeSets[i]).Changes)
{
// As long as the changes are not related to Team Build Types/build Definitions...
if (!change.Item.ServerItem.Contains("BuildDefinitions"))
//if (!change.Item.ServerItem.Contains("TeamBuildTypes"))
{
// Create source control version of the label.
ItemSpec changesetItemSpec = new ItemSpec(change.Item.ServerItem, RecursionType.Full);
labelItemSpec.Add(new LabelItemSpec(changesetItemSpec, new ChangesetVersionSpec(changeSets[i]), false));
}
}
}
}
/// /// Trigger a build of the labeled items. /// /// Label for the build /// Success/failure of the build public bool TriggerLabeledBuild(string label) { try { // Add the obtained changesets to the list. List BuildChangesets = new List(); foreach (int cs in changeSets) { BuildChangesets.Add(tfvc.GetChangeset(cs)); }
// Get the Build Definition Object.
IBuildDefinition buildDef = bs.GetBuildDefinition(project, selectedBuildType);
// Create a Build Request object.
IBuildRequest request = buildDef.CreateBuildRequest();
// Specify that we want a labelled version of the build.
request.GetOption = GetOption.Custom;
request.CustomGetVersion = "Label Demo";
// Queue our build.
queuedbuild = bs.QueueBuild(request);
// Get the build details of the Queued Build so that we can associate the changesets to it.
build = queuedbuild.Build;
// Associate the non-default changesets to the build.
List<IChangesetSummary> assocChangesets = InformationNodeConverters.AddAssociatedChangesets(build, BuildChangesets.ToArray());
// Start a timer for the build.
timer = new System.Timers.Timer(5000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.Start();
return true;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}