How to use the same label in TFS? - tfs

I am trying to use labels in TFS. I understand that labels have scope but I don't understand why am I getting an error:
A label with the name 'CB-ARCHIVE-2018' already exists. Do you want to continue? The existing label will be replaced.
I created a ('CB-ARCHIVE-2018') labeled for '$/SourceCode/WebService' and I am trying to use the same label for folder '$/SourceCode/WebService-branch'.
Thank you!

When you use Visual Studio to apply a label that already exists, the operation removes the label from all file versions and then applies the label. From the command prompt, however, the label operation is additive. See Label Command (Team Foundation Version Control). So use tf command to add the exist label:
tf label CB-ARCHIVE-2018 $/SourceCode/WebService-branch /collection:http://tfs:8080/tfs/DefaultCollection
Check the link below for more information:
https://learn.microsoft.com/en-us/vsts/tfvc/use-labels-take-snapshot-your-files?view=vsts#apply-a-label

Labels are a bit if a confusing beast in TFVC, mostly because the Ui doesn't enable all options.
From the Ui the scope is always set to $/. The path you specify tells Visual Studio which files/folders to include in the label.
You could try adding #$/SourceCode/Webservice to the label name, not sure if that works.
The sure way to specify a label scope is from the commandline from where you can issue the following command to apply the label:
tf.exe vc label CB-ARCHIVE-2018#$/SourceCode/Webservice $/SourceCode/Webservice
Label scopes can't intercect, so you'll probably need to delete the existing labels first.

Related

Adding new "tab" to a bug work item in TFS 2017

I am trying to add a new "tab" to bug item in TFS 2017. Looking at the "tabs" you see things like "Steps to Reproduce", System, etc.
I have found information on changing work item types but nothing about adding a new "tab" across the top where you see Steps to Repro, System, Test Cases, Tasks. The change I want to make may not be possible? Or it is possible I don't know the correct verbiage to use when asking google. The think I want to change may not be a tab control at all it maybe something else different.
Thanks
***************** Updated questions after posting *****************************
After playing around with Process Editor -> WIT -> Open WIT from server -> Bug
as suggested by Andy Li-MSFT I don't see a lot of control on the formatting on the tab. I was planning to add fields in a grid like pattern like a table as shown below. I am able to get the values in the drop down list for field1 and add the fields. However I have a couple follow up questions if you have time.
Setting either the control or column for the control to read-only the column will not render when adding a new bug. I have a little more control if I set AllowedValues and Frozen for the column however the value can still be changed. Is there a better way to set read-only?
There is not much control on the layout. I am OK adding a lot of fields but would like them to be displayed in a table like structure. Is there a way to control the look of the fields on the form?
Is there a way to add the fields in a grid? This would be ideal so I only have one header for each column.
The last-updated-by and last-updated-date. Is it possible to track on a row level who made a change? If not I would be OK just adding a last updated by and last updated date to the new tab. Row level updates would be nice.
<pre>
Field 1 Field 2 (Read-only) Field 3 Last Updated By Last updated Date
Status (completed, empty, N/A) "Some text here which describes something to do" "Optional comments" tfs user name date/time
Status (completed, empty, N/A) "Some text here which describes something to do" "Optional comments" tfs user name date/time
</pre>
You need to modify the WIT definition file (Bug work item type in your scenario).
You can try below ways to do that:
Export the WIT definition file with witadmin commands, add a new tab under <TabGroup> and add a new control for it, then save and import the file. See Import, export, and manage work item types for details.
e.g:
<Tab Label="Tab0501">
<Control FieldName="System.ChangedDate" Type="DateTimeControl" Label="Test0501:" LabelPosition="Left" />
</Tab>
You can also use the TFS Power Tools to export/import WIT definition files or directly modify the files from server:
Visual Studio 2015 : Microsoft Visual Studio Team Foundation Server
2015 Power Tools
Visual Studio 2017 : TFS Process Template Editor
Reference below screenshot to do that.
Another way is writing an extension to Extend the work item form, you can reference my answer in another thread to do that.

TFS Build 2015 - using custom variables in label format

TFS Build allows to define a label format in "repository" tab in build definition. I can define custom variables in "variables" tab and use them in label format definition. But is there any possibility to change a value of such custom variable in batch script in custom build step? Or maybe in some other type of a build step? I can get a value of such variable in a batch script, but any changes are ignored (though "Modify Environment" checkbox is set). Is there any possibility to use a value calculated during a build process as a part of a label format?
Thanks in advance!
It should be. There is no much difference with the custom variable in "variables" tab and custom variable in batch script in custom build step.
However, please note not every custom variable can be used as a part of a lable format. Please double check this.
Some build variables might yield a value that is not a valid label.
For example variables such as $(Build.RequestedFor) and
Build.DefinitionName can contain white space. If the value contains
white space, the tag is not created.
Update from OP: As a workaround, with build.updatebuildnumber you could update a build number and then use $(build.buildNumber) in label format.

TFS 2012 Build Definition/Template - How to set Build Quality Automatically?

I thought this would be pretty straight forward, but it looks like the template has to be modified. Anyone have any idea what to do to add this piece to the default template?
I know how to edit the templates, I just don't know what I need to do to make this work.
This case already provided a solution for your requirement:
Copy the DefaultTemplate.xaml to DefaultTemplateCustom.xaml and open it
Click the Collapse All link in the top right corner
Open the toolbox and locate the Assign activity. It is located in the Primitives section
Drag the Assign activity to the end of the workflow, after the "Run MSBuild" activity
Go to the properties window. Set the "To" parameter to BuildDetail.Quality. Set "Value" to "xxx (Build Quality)"
Locate the InvokeMethod in the toolbox and drag it and drop it after the Assign activity
Set the "Target Object" to BuildDetail. Set "MethodName" to Save
Save the build definition xaml file and check it in, then build with the customized definition.
You can also consider to create a powershell script to set the build quality via TFS API and then invoke this powershell script in your build template. Refer to this link for details: PowerShell and TFS: The Basics and Beyond.
Here is a simple script to set the build quality:
$builduri = "vstfs:///Build/Build/1";
$collectionurl = "http://xxxx:8080/tfs/xxx/";
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($collectionurl);
$buildservice = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer]);
$build = $buildservice.GetBuild($builduri);
$build.Quality = "Released";
$build.Save()

TFS Label Inconsistency

I've been working with Team Foundation Server 2012 to get a Continuous Integration build for a data warehouse project working. In doing so I noticed that the labeling and building from a label wasn't yielding the results that I was expecting. In researching the problem I was able to replicate the issue using only the command line arguments provided by Team Foundation Servers Command Line tools. That helped me to eliminate anything in the build definition that may have been affecting the build.
So this is my problem:
I have a build that is building 2 different projects in a single build. It basically has two *.SLN files associated with it. I applied a label to 2 assets, one in each project. I can then execute the command to view which assets have the label. When doing this I get the expected result. However, when I execute the command to get the assets associated with this label it only pulls 1 of the two files. I've verified that I can pull both files, by removing one of the projects. This is the setup that I have with the build definition, work space and label
TFS Paths: $/Dev/Project1
$/Dev/Project2
Workspace Mapping
Project1: C:/SourceControl/Project1
Project2: C:/SourceControl/Project2
DeploymentFolder
Project1: //DevServer/SSIS/Project1
Project2: //DevServer/SSIS/Project2
Executed Commands:
Apply Label: tf label TestLabel $/DEV/Project1/PackageA.dtsx
tf label TestLabel $/DEV/Project2/PackageA.dtsx
Review Label: tf labels /format:Detailed LTestLabel
Get From Label:
tf get /r /version:LTestLabel
After executing the tf get command I get the following results
Deployment folder: //DevServer/SSIS/Project1 contains the file PackageA.dtsx
Deployment folder: //DevServer/SSIS/Project2 contains 0 Files.
It appears that there is a filter or restriction on pulling assets in different projects with the same label. I would expect that if I apply a label to any asset in TFS, then pull the labels, it should allow me to retrieve all assets with that applied label. Has anyone heard or experienced this? Any help provided would be appreciated.
You don't specify what (local) folder you're in when you execute the get: since you don't specify a folder to get, it implies the current one, equivalent to:
tf get /recursive /version:Llabelname .
If you want to get both, specify a directory containing both, for example:
tf get /recursive /version:Llabelname $/
This, of course, assumes that both the files in your label are mapped.

Get labels applied to a particular version of an item in TFS source control

I'm trying to get a list of labels that apply to a particular version of a particular file in TFS Source Control. So far, I've gotten a set of labels that apply to any version of a particular file. Does anyone have any experience getting labels for a particular item?
For example, I have $/Project/Folder/Item.cs, which was modified in changesets 301, 401, and 601. Labels Build1 - Build 99 exist for the project. Build1 - Build10 were applied before changeset 301 (i.e. before Item.cs was created). Build96 - Build99 were applied to the v601 of Item.cs. If I run
vcServer.QueryLabels(null, "$/Project", null, false, "$/Project/Folder/Item.cs", new ChangesetVersionSpec(6))
I get Build11 - Build99 as results. I haven't figured out how to get a query to return fewer than this many labels. Ideally, the query I run will return 4 labels (Build96 - Build 99).
The context of this question is a TFS Project, with CCNET for a build server. I'm trying to relate work items to builds, starting with a work item number.
Any tips? Or examples of QueryLabels? Or better docs for QueryLabels than the MSDN docs?
This is possible, see here: http://social.msdn.microsoft.com/Forums/en-US/tfsversioncontrol/thread/9f41f37e-4fda-4b56-91a3-f2b7e0c0e22d
Basically, once you get back the list of labels, you have to look through each label and see what changeset of the item you're interested in it applies to. Be sure to pass in the "includeItems = false" flag to QueryLabels, otherwise you'll have to look through every item on the label.
What you are wanting to do should definitely be possible using the API. The answer I gave to the other question was about seeing the labels inline with history in the UI.
For more information about doing what I think you are wanting to do, then take a look at:
Buck Hodges: Finding the changes between two labels in TFS version control
and also
Manish Agarwal: What is GenCheckinNotesUpdateWorkitem task?
Hope that helps.
Martin.
It looks like it's not possible with the current TFS version, but may be with the next.

Resources