I was trying to use new Build on Visual Studio Team Services (not XAML) but couldn't figure out how to label the source upon successful build. Any idea?
Below is the screenshot that shows how to do in XAML one.
I already have a feature request at https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/9613014-allow-label-source-upon-succesful-build-on-visual I'm actually asking for a workaround until Microsoft implements it.
I just noticed that the feature is now available in build vNext. Its configuration is in the Repository tab in the build definition.
I think Yves Dierick's answer was correct back in October 2015, but the layout of the VSTS screens has changed a lot since then. In the latest version (as of February 2017), you can add a label to a successful build by selecting the Get Sources task in the Build Definition, choosing show Advanced Settings in the top-right corner and then selecting the On success radio button under the Tag Sources section that appears.
Took me a while to find it, so I thought it might help someone else. It doesn't help that this option is under "Tag sources" and doesn't mention the word "label" at all.
Update 13/03/2018
They've tweaked the layout of this page again, but made it simpler if anything, and now the option is more helpfully named "Label Sources".
For those of you running across this thread looking for a solution to TFS hosted (not VSO), note that support for build labels came out in TFS 2015 Update 1: https://www.visualstudio.com/en-us/news/tfs2015-update1-vs.aspx
We're not running Update 1 yet, so I can't confirm.
Edit: We're now running Update 1 (and 2, actually), and label build sources works for on-prem.
The Label Sources feature is unavailable in vNext build.
Besides the Label Sources feature, the Associate Work Items and Create Work Item on Build Failure features are unavailable as well.
You can submit one feature request about it on the Microsoft UserVoice site: https://visualstudio.uservoice.com/forums/121579-visual-studio/category/30925-team-foundation-server-visual-studio-online
The XAML build did label sources at the start of the build, while vNext build seems to label at the end of the build.
I noticed that, because I modify/checkin/label files during the build.
If I let vNext label the build, it moves the label that I have applied to the files after checkin to the previous version (the version that was used in GetSources).
But I did not see the labeling of vNext in any logfile. Did I miss it?
I will have to disable labeling in vnext and do it in my msbuild script...
edit:
Disabled labeling in vnext build definition and created an msbuild inline task to label the sources of the workspace. Now I can label all sources at the start of the build and move the label for files that were modified during the build :)
If someone wants to do something similiar, here is my inline task:
<!--
TaskName="LabelWorkspaceSources"
- input: TfexeFullPath is the path to tf.exe
- input: BaseDirectory is the mapped folder of the software to build
- input: Label to apply
- input: Version is the changeset to apply the label to
-->
<UsingTask TaskName="LabelWorkspaceSources" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<TfexeFullPath Required="true" />
<BaseDirectory Required="true" />
<Label Required="true" />
<Version Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
//--- get the workspace mapping ---
System.Diagnostics.Process tfProcess = new System.Diagnostics.Process();
tfProcess.StartInfo.FileName = TfexeFullPath;
tfProcess.StartInfo.Arguments = "workfold";
tfProcess.StartInfo.UseShellExecute = false;
tfProcess.StartInfo.CreateNoWindow = true;
tfProcess.StartInfo.RedirectStandardOutput = true;
tfProcess.StartInfo.WorkingDirectory = BaseDirectory;
tfProcess.Start();
string output = tfProcess.StandardOutput.ReadToEnd();
tfProcess.WaitForExit();
string workfoldOutput = output.Trim();
Log.LogMessage(workfoldOutput, MessageImportance.High);
string[] linesWorkfoldOutput = workfoldOutput.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
List<string> mappedFolders = new List<string>();
Log.LogMessage("Trying to parse mapped folders.", MessageImportance.High);
foreach (string line in linesWorkfoldOutput)
{
//e.g. $/TPA: C:\TFS_Source\TPA
if (line.Contains("$/"))
{
string[] lineSplit = line.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries);
//entry lineSplit[0] now contains the server path, lineSplit[1] contains the local folder
mappedFolders.Add(lineSplit[1]);
Log.LogMessage("Found mapped folder: " + lineSplit[1], MessageImportance.High);
}
}
//--- label all the mapped folders ---
foreach (string mappedFolder in mappedFolders)
{
tfProcess = new System.Diagnostics.Process();
tfProcess.StartInfo.FileName = TfexeFullPath;
tfProcess.StartInfo.Arguments = "label " + Label + " \"" + mappedFolder + "\" /child:replace /recursive /comment:\"Label created by task LabelWorkspaceSources\" /version:" + Version;
tfProcess.StartInfo.UseShellExecute = false;
tfProcess.StartInfo.CreateNoWindow = true;
tfProcess.StartInfo.RedirectStandardOutput = true;
tfProcess.StartInfo.WorkingDirectory = mappedFolder;
tfProcess.Start();
output = tfProcess.StandardOutput.ReadToEnd();
tfProcess.WaitForExit();
Log.LogMessage(tfProcess.StartInfo.Arguments, MessageImportance.High);
Log.LogMessage(output, MessageImportance.High);
}
]]>
</Code>
</Task>
</UsingTask>