Naeem Sarfraz

Blogging about Enterprise Architecture, ALM, DevOps & happy times coding in .Net

Release Management 2015: Copying Failed for Robocopy, Component Name Must Match Artifact Name

Overnight we upgraded our on-premise TFS 2015 installation applying Update 3 and this morning I came in to find all our overnight builds failed. Our overnight CI builds, trigger a release in Release Management deploying the latest version of our applications to our dev environment. The problem lay with the Release Management upgrade (Release Management Client for Visual Studio 2015 Update 3).

Release Management reported the following error.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> Microsoft.TeamFoundation.Release.Common.Helpers.OperationFailedException: Deployment started on
target machine...

System.AggregateException: Failed to execute the powershell script. Consult the logs below for
details of the error.
Copying failed. Consult the robocopy logs for more details. ---> System.Management.Automation.RuntimeException:
Copying failed. Consult the robocopy logs for more details. ---> System.Management.Automation.RuntimeException:
Copying failed. Consult the robocopy logs for more details.

2016/07/01 05:03:53 ERROR 2 (0x00000002) Accessing Source Directory \\SERVER\Builds\APPLICATION\1683\Web\Web\
The system cannot find the file specified.

Back to Basics

We have a convention for our TFS builds where using the Publish Artifact Task we’ll organise the contents of the build Artifacts in folders: Web, SQL or App.


Each folder in the TFS Build Artifacts will have a one-to-one mapping to a Release Management component similar to this.


The Path to package normally points to the root of the TFS Build Artifacts folder and we add the word Web so that the component will look for the deployable bits in this folder. This is the only bit I could link back to the error as I saw robocopy was attempting to copy from a folder path that ended with ..\Web\Web. I quickly setup a new component and played around to come across this error.

ERROR: 0 artifact(s) found corresponding to the name 'vNext-Deploy-DEBUG' for BuildId: 1693.
Rename the component such that it matches uniquely with any of the available artifacts of the
build : SQL, Web.


Aha. The last error pointed to the fact that your published artifact (top level folders in your TFS Build Artifacts) must match the name of the component defined in Release Management. In fact I found that it doesn’t have to match the name exactly but the component should contain the name of the artifact. A typical example of the name we use is vNext-DeploySalesApp-WebApp. 

The word Web in the Path to package field would explain why it tried to copy files from ..\Web\Web. Now this box cannot be left empty so we replaced it with .\ and normal service is resumed.

P.S. Very soon we’ll be glad to see the back of Release Management in its WPF client form and move all our releases to the new version which runs out of the TFS site. Can’t wait.

Trigger an Agent Release from TFS 2013 Build

You’re using TFS 2013 to build your application continuously, or on a schedule or both giving you feedback on how good your team are doing at integrating their work with one another. Using Release Management (RM) you can deploy your application into your Dev environment, then UAT and finally Production all at the click of a button. This post describes how you can trigger that build from a TFS 2013 build.

How could you use this and why? A product team wants to deploy to a Dev environment on every commit to the central repository. This environment is used by the developers to test the integration of all of the different components of a product before releasing into UAT. This can be described as Continuous Deployment. If the product has many components to it you may not want to deploy on every commit instead you could deploy daily as a result of a scheduled build e.g. a nightly build.

You can do this by triggering a release from a TFS build by modifying the build process template, used by your build definition, of which there are several:

  • DefaultTemplate.xaml
  • GitTemplate.xaml
  • TfvcTemplate.xaml
  • UpgradeTemplate.xaml

Installing the new build process template

Install RM and new versions of the above templates are installed on your server for you to use. On the server where you have installed RM Server go to C:\Program Files (x86)\ Microsoft Visual Studio 12.0\ReleaseManagement\bin\ where you’ll find the following files:

  • ReleaseDefaultTemplate.xaml – TFS 2010
  • ReleaseDefaultTemplate.11.1.xaml – TFS 2012
  • ReleaseGitTemplate.12.xaml – TFS 2013
  • ReleaseTfvcTemplate.12.xaml – TFS 2013
  • ReleaseUpgradeTemplate.xaml – TFS 2010

You can also find these files on a machine where you have installed the RM client application, the location is C:\Program Files (x86)\Microsoft Visual Studio 12.0\Release Management\Client\bin (just be aware that some have reported the templates in the RM Client directory might not work). The RM client can be downloaded from your MSDN subscription or from here which is a limited trial version. Now add these files to source control by creating a folder called BuildProcessTemplates at the root of your Team Project repository and drop these files into there and commit (or checkin) so the path looks something like (for TFSVS) $/MyTeamProject/BuildProcessTemplates/ReleaseTfvcTemplate.12.xaml.


Configure your build

Create your new build and select one of the new templates:


You’ll want to take note of the following RM-specific properties:


  • Configuration to Release – String array, normally set to Any CPU|Release
  • Release Build – Boolean value (true or false), true if you want to trigger the release
  • Release Target Stage – String value, if you set this to the name of one of your RM stages e.g. DEV, PROD if you want to deploy into that enviornment only otheriwse leave blank

The new release process templates trigger RM by making a call to ReleaseManagementBuild.exe, which you’ll get when you install the RM client. This means wherever you have a TFS Build agent installed you will need to have the RM client also installed on that machine.

Trigger a new build and confirm that your release was created and then triggered ReleaseManagementBuild.exe. Using the RM client you should see a new release created.

Modifying an existing build process template

You may have modified one of the default templates or created your own version of it in which case you will want to add the RM capabilities to it. There is a post over at MSDN on the Visual Studio ALM blog that details exactly how to do this.

An Alternative Method to Timestamp a File or Folder in Release Management 2013

In a previous post I presented a powershell script to attach a timestamp suffix to files or folders backed up prior to a deployment. At the point of writing that post I wasn’t aware of a collection of runtime variables that are available in your powershell script.

Below is alternate script to the last one I presented. The suffix in this script is not using the current date and time but the $ReleaseId variable which is a number. Each time a new released is created and executed this variable will contain a new value but remember a release maybe re-tried in which case this value will not change. You could also use the $BuildNumber variable (alter line 7) which is the unique Id TFS assigns to the build and is a number.

Runtime Variables in Release Management

Deploying a vNext release means you can take advantage of global variables in your powershell script. A complete description of what is available and how you can configure your own is available here.

Here is a simple script which I found useful when you simply want to know\confirm the values being pushed to your script. The end of the script will also dump out all variables (undocumented ones) to the logs too.

Timestamp a File or Folder in Release Management 2013

TLDR: Download and use this powershell script in your deployments to append a timestamp to a file or folder.

Typically you’ll backup a database prior to upgrading it through Release Management or you’ll copy a website folder to a backups folder as part of your rollback strategy. Both tasks are easily achieved using the Backup SQL Database and Copy File or Folder tasks.

RM Web DB tasks - no unique name

You’ll most likely want to version your backup copies using a timestamp strategy. This would involve passing some sort of token which can be evaluated at runtime and your input value modified to accommodate this token and this is where we find RM wanting. For example you can’t use a token such as __BuildID__ in the DestinationFileFolder (Copy File or Folder task) like so D:\Sites\InvoiceApp\Backups\InvoiceWebapp__BuildID__. The input fields simply won’t recognise any token so our only option is to follow up the task with a new one that will rename the newly created file or folder.

PowerShell to the rescue

Here is a powershell script which can be can be used to rename either a file or a folder. By default it will append a timestamp in the format yyyyMMddhhmmss but you can override that to match your requirements.

To begin to use this in RM you will need to create a Tool like this:

RM RenameObject Tool

And then create a couple of Actions like this:

RM RenameObject Action File RM RenameObject Action Folder

And finally use it in your template like this:

RM Suffix file RM Suffix Folder

An approach that didn’t work

For completeness I’m including an approach that didn’t work me and I never got to the bottom of why it never worked.

From the command line I can rename a file or folder using xcopy whilst at the same time I can use %date% and %time% to create a timestamp. A typical command would look like this:

xcopy D:\Sites\AppA\Current D:\Sites\AppA\Backups\AppA_%date:~-4,4%%date:~-7,2%%date:~-10,2%%time:~-11,2%%time:~-8,2%%time:~-5,2%%time:~-2,2% /I /E

You’d think then if I used this command in the Run Command Line task that we have the desired behaviour well RM doesn’t like this command. An error occurred from the task which looked like it was trimming down the command. I gave up after a few hours and pursued the solution above.