Showing posts with label TfsBuildCustomization. Show all posts
Showing posts with label TfsBuildCustomization. Show all posts

Saturday, April 2, 2016

How to define build variables like SourcesDirectory, BinariesDirectory, TestResultsDirectory in TFS 2013 Default Build Template (TfvcTemplate.12.xaml)


In this post I will explain the steps to create build variables like SourcesDirectory, Binaries Directory, and TestResultsDirectory in TfvcTemplate.12.xaml.
By default we will not be able to use above variables in TFS 2013 default build template as how it’s there in TFS 2012/TFS 2010.
In order to get all these variable with proper path follow below steps.
1.      Download TfvcTemplate.12.xaml file from TFS and add the file to Source Control.  
2.      Create variable named SourcesDirectory, BinariesDirectory and TestResultsDirectory.
Open TfvcTemplate.12.xaml file and click on Run on agent workflow and then on Variable below the page.
Now create three variables named SourcesDirectory, BinariesDirectory and TestResultsDirectory as shown below. 

3. Now Open Toolbox (View -> Toolbox) and search for GetEnvironmentVariable activity.


4.      Select GetEnvironmentVariable<T> activity under Team Foundation build Activities and drag and drop it to TfvcTemplate.12.xaml  after the activity Update build number, on pop up change the type to String.




5.      Select the activity on the TfvcTemplate.12.xaml file and open properties window.
Change the property values as below.
 
Name: Microsoft.Teamfoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.SourcesDirectory
DisplayName: Get Sources Directory
Result: SourcesDirectory
6.    Add two more GetEnvironmentVariable<T> activities for TestResultsDirectory and Binariesdirectory with type String and set the property values as below respectively.

Property values for TestResultsDirectory
Name:
Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.TestResultsDirectory
DisplayName: Get Test Results Directory
Result: TestResultsDirecotry

Property values for BinariesDirectory
Name: Microsft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.BinariesDirectory
DisplayName: Get Binaries Directory
Result: BinariesDirectory
7. Save the changes and then check-in to the server.





 

Enabling logging verbosity process parameter in build definition



   Verbosity for a build will help us to debug the build results to see what exactly went into build. In TFS 2013, default build process template TfvcTemplate.12.xaml verbosity level is set to “Normal” by default and if we need to change the verbosity level we have to download and open the template and set the Verbosity property value of RunMsBuild activity to Detailed or Diagnostic or Minimal (Image 1.0) and then check-in in TFS and then upload it to build.
 Image 1.0
Also this change is applicable for all the build definitions which makes use of build template. So it is not maintain different verbosity levels for all build definitions. And if we observe the default build process template (TfvcTemplate.12.xaml) of TFS 2013 we will not find the logging verbosity parameter to set it Minimal, Normal, Detailed or Diagnostic. (This option is available for TFS 2012 or TFS 2010 build templates by default). But this can be achieved by little customization to the template

Steps to enable the logging Verbosity parameter in Build definition process tab.

Download the template TfvcTemplate.12.xaml from build definition wizard and add it to the version control folder.

Now open this file in Visual Studio and you can see the workflow defined for TfvcTemplate.12.xaml template. Click on Arguments tab down the page and create new argument called Verbosity.
Let the argument Direction be “In” and change argument type to “Microsoft.TeamFoundation.Build.Workflow.BuildVerbosity”. And set Default value asMicrosoft.TeamFoundation.Build.Workflow.BuildVerbosity.Normalas shown in Image 1.1
 Image 1.1
This completes defining the build argument and setting its default value. Now let’s make this argument be available in build definition Process Tab.
For this, click on Metadata argument in the argument tab and click on the ellipses (…) button under default value column of Metadata argument shown in Image 1.2
 Image 1.2
This will open “Process Parameter Metadata Editor” window shown in Image 1.3
Image 1.3
               In “Process Parameter Metadata Editor” window we can add the parameter that has to be appeared in build definition process parameters Image 1.4
Image 1.4
Let us add the parameter Logging verbosity parameter under category 2. Build after 5. Advanced parameter i.e. 6. Logging verbosity
To do this, open” Process Parameter Metadata Editor” and make note of make note of parameter ProjectsToBuild, because we are adding parameter under same category. Image 1.5,in our template category value is #200 Build
Image 1.5
Now click on Add button and give details as shown in Image 1.6.

Parameter Name : Verbosity
Display Name : 6. Logging verbosity
Category : #200 Build
Description : Specify the level of logging desired for this build. Higher verbosity levels will typically result in slower builds.
Value Format String : Microsoft.TeamFoundation.Build.Workflow.BuildVerbosity
View this parameter when : Always show the parameter

Refer figure Image 1.6

Where Parameter Name should be same as argument name defined, Display Name how you want to display this parameter in build definition, Category under which category you want to display the parameter, Description explains the parameter in build definition and View this parameter when for enabling this parameter either only in build definition or only when queuing the build or both definition and queuing the build or never.
Image 1.6
Then click ok and save the changes then check-in the template to Source Control. Use this customized template in build definition and you will be able to see the new parameter logging verbosity as shown in Image 1.7
Image 1.7
Create a new build definition and while queuing you can edit this verbosity value in queue build parameter window as shown in Image 1.8
Image 1.8
  Thank you for reading this blog.