Category Archives: 3271

Getting the compile and test status as environment variables when extending TF Build using scripts

The Goal

When running custom batch or PowerShell scripts as part of TF Build, you want to access the compilation and test result using an environment variable.

The Solution

When you use the new TfvcTemplate.12.xaml build process template, it’s easy to run additional scripts or tools as part of the build process.

There is a tool available (TfbEnv.exe) that will create additional environment variables with the compilation/test results. It is free and can be downloaded here.

The tool will always set the following two environment variables:

  • TFB_COMPILATIONSTATUS
  • TFB_TESTSTATUS

The value corresponds to the current result (Succeeded, Failed, Unknown).

Additional environment variables:

  • If compilation succeeds, TFB_COMPILATION_SUCCESS is set to 1.
  • If compilation fails, TFB_COMPILATION_FAILED  is set to 1.
  • If tests succeed, TFB_TEST_SUCCESS is set to 1.
  • If tests fail, TFB_TEST_FAILED is set to 1.

How to use it

There are two ways to use it:

Option 1: Use TfbEnv.exe to generate a batch file which you can call from your scripts to set up the environment variables

  1. Create a batch file that invokes TfbEnv.exe and then calls “SetVars.bat” (which is created by TfbEnv.exe).

    Here’s a very simple example:

    TfbEnv-Batch-File
    (Note: In this example TfbEnv.exe is stored in a “build” folder in Version Control)
  2. In your build definition, set “Post-test script path” to run your batch file:
    TfbEnv-Batch-Parameters
  3. Done. Queue a new build!

Option 2: Use TfbEnv.exe to invoke your batch oder PowerShell script file with the additional environment variables available

  1. In your build definition, set “Post-test script path” to run TfbEnv.exe.
  2. Under Post-test script arguments use the “run” argument to specify the batch file or PowerShell script that you want to run.

    Here’s an example:

    TfbEnv-PowerShell-Parameters
    Figure: In this example, TfbEnv will set up the environment variables
    and then execute the PowerShell script “PostTest.ps1”
  3. Done. Queue a new build!

Note: TFS 2013 Update 2 (2013.2) is required. If you are not on Update 2, you can explicitly use the /collection (or just "/c") parameter to specify your TFS Collection URL.

Enjoy!

–Neno

 

Updated (May 21, 2014): Added a note that TFS 2013 Update 2 is required (+ workaround).

Updates (May 25, 2014): Updated this blog article to explain how to use the tool (2 options).

Writing the Build Report with Associated Changesets and Work Items to a file as part of the build

The Goal

TFS has a nice Build Reporting, including a list of associated changesets and work items (if any). You might want to have this information saved to a file during a build.

Figure 7.6 Build Report

The Solution

When you use the new TfvcTemplate.12.xaml build process template, it’s easy to run addition scripts or tools as part of the build process.

There is a tool available (TfbNotes.exe) that generates a build report in .TXT and .XML format. It is free and can be downloaded here.

All you need is to check-in the file into version control and reference it in the build process, for example at “3. Test” » “2. Advanced” » “Post-test script path”.

TfbNotes_Process

Note: To run more than a single tool, use batch files or PowerShell scripts.

Here’s how the .TXT output looks like:

TfsNotes.exe

Note: TFS 2013 Update 2 (2013.2) is required. If you are not on Update 2, you can explicitly use the /collection (or just "/c") parameter to specify your TFS Collection URL.

Enjoy!

–Neno

Updated (May 21, 2014): Added a note that TFS 2013 Update 2 is required (+ workaround).

When to use the Test Attachments Cleaner (and when not)

What is the Test Attachment Cleaner?

A command line tool that only removes the attachments. It does not touch the test runs, which contain the pass/fail data. So, running Test Attachment Cleaner will not impact the record of the test runs.

You need to Test Attachment Cleaner if you:

  • Do manual test runs and want to delete attachments without deleting the test runs
  • Do automated test runs and want to delete attachment for builds which have been deleted already, but the build definition’s retention policy was not set to delete “test results” (because this is turned off by default)

You do not need the Test Attachment Cleaner if you:

  • Have automated test runs triggered by a build, and you have configured the build definition’s retention policy to delete “test results” (which is not set by default)
  • Delete the Test Runs manually (as this deletes the attachments)

Where do I get it from?

The Test Attachment Cleaner is available as part of the TFS Power Tools:

(Thanks Ravi Shenker from Microsoft for the input!)

SOLVED: Error ‘(405) Method Not Allowed’ when publishing a NuGet package to a NuGet server

The Problem

When trying to publish NuGet Packages to a NuGet server you get the error message:

Failed to process request. 'Method Not Allowed'.

The remote server returned an error: (405) Method Not Allowed.

The Solution

Found in this post on stackoverflow.com:

When you LIST packages in NuGet server you point to http://nugetserver.com/nuget. However when you are trying to PUSH or DELETE a package you need to point to http://nugetserver.com without the nuget folder in the path.

Good luck!

–Neno

Build fails with missing file: System.Management.Automation.dll

The Problem

  • The Build breaks with the following message:

Exception Message: Could not load file or assembly ‘System.Management.Automation, PublicKeyToken=31bf3856ad364e35′ or one of its dependencies. The system cannot find the file specified. (type FileNotFoundException)

The Solution

The Cause

  • You might be using the Community TFS Build Extensions. These include the InvokePowerShellCommand activity, which has a dependency on this .DLL

–Neno

Build fails to find GraphCmd.exe (Layer Diagram Validation)

The Problem

  • The Build breaks with the following message:

Error message:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.LayerDesigner.targets (148): The "GraphCmd" task failed unexpectedly. System.InvalidOperationException: Cannot start process because a file name has not been provided.

The Solution

Add this xml snippet into all of your Modeling project (*.modelproj) files:
<PropertyGroup>
    <GraphCmdPath Condition="’$(GraphCmdPath)’==” and ‘$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\Architect@GraphCmdDir)’ != ”">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\Architect@GraphCmdDir)</GraphCmdPath>
</PropertyGroup>

–Neno

How to compile projects that reference Microsoft.Office.Interop assemblies with a build server

The Problem

A project that references Office interop assemblies (Microsoft.Office.Interop) fails to compile on TF Build (or VSO’s Elastic Build Service).

The error message might be similar to this one:

The type or namespace name ‘Office’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)

The Solution (based on this forum post)

You want to check-in the interop assemblies.

  1. Create a “Lib” folder and add all relevant assemblies, like:
    • Microsoft.Office.Interop.Word.dll
    • Microsoft.Office.Interop.Excel.dll
    • Microsoft.Vbe.Interop.dll
    • OFFICE.DLL
  2. Removed the references to your Office interop assemblies and add references to the assemblies in your libs folder.

–Neno

TFS Build cannot resolve dependency to assembly ‘Microsoft.Windows.Design.Extensibility’

The Problem

  • You are using DevExpress components.
  • Compilation fails with the message:

‘Cannot resolve dependency to assembly ‘Microsoft.Windows.Design.Extensibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

The Solution

  • Check your references and remove any reference to DevExpress.*.Design.dll’s.

(Thanks to "Kookiz" who solved this.)