5 minute read

To setup a build in combination with Release Management you need the Release Management build template. This template looks like the default build template but has an additional sequence action to start the release after the build is succeeded. The Release Management Build template can be found within the install location of release management.

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Release Management\Client\bin\ReleaseTfvcTemplate.12.xaml

We will use this template and rename it to “BuildTemplate-Release-General.xaml”. As location for the build template we will use TFS project called: “Build Templates”. By using a central location we make sure we will not have duplicate build templates within our Team Foundation Server environment.

For different types of builds you would like to add files to your drop location that you save within a solution folder for this we will have to make a small adjustment to our build template. To make this adjustment open the Build template and navigate to the sequence activity that contains the “msbuild” action.

You can find the “msbuild” activity by following the following path:

“Overall Build Process” – “Run on Agent” – “Try” – “Compile, Test and Publish”.

In the sequence activity that contains the “msbuild”  action we will add two argument by selecting “Compile, Test and Publish” and then Arguments in to lower left corner. If you scroll down the list click on “Create Argument” to add a new argument.

image

Add the following arguments:

  • CopySolutionFolder: Will be used to save the location of the Solution folder relative to the Team Foundation server.
  • DropLocation: Will be used to save the drop location of the build.
  • CustomBuildDirectory: Will be used to save the location of the Solution folder on the build server.

image

Know that we have created the argument we can add actions to set the values of the arguments. Drag a “GetEnvironmentVariable<T>” action to the top of the “Compile, Test and Publish” sequence and call it “Get Drop Location Folder” and set the properties as you can see in the image.

image

The “WellKnownEnvironmentVariables.DropLocation” is the environment variable we need in order to get the drop location of the build. In the result property define the argument (“DropLocation”) in which you want to save the value.

Place an “If” control flow underneath the “GetEnvironmentVariable” action to check whether the value of the argument “CopySolutionFolder” is not null or empty. This because we will define this argument within the build definition interface. You can add an argument to the build definition interface by updating the Metadata Argument. Select this argument and edit it by selecting the three dots within the default value column.

image

Scroll down the list of parameters and check whether the argument you created is in the list. If this argument is not already in the list add it.

 

image

In the If control flow we check if the value of the “CopySolutionFolder” argument is not null or empty by defining the following condition:

String.IsNullOrEmpty(CopySolutionFolder)

If the argument is null or empty we will not take any action and if it contains a value we will try to get the local path of the solution folder in order to copy the contents to the drop location. To achieve this we need to add a sequence action to the else branch.

image

To retrieve the local path of the solution folder we place the “GetLocalPath” activity in the sequence. This action will allow us to add a TFS project relative path in the build definition. For example the value could be: “$/SharePoint Portal/MSFTPlayground.SharePoint.Farm/Deployment Configuration”. The result of the “GetLocalPath” action will be saved in the CustomBuildDirectory argument.

image

To finalize the build definition we add the “CopyDirectory” activity to the sequence. The source of the activity will be the solution folder (“CustomBuildDirectory”) and the destination will be the drop location (“DropLocation”).

image

Save the build template and check the file in into TFS. With the file in TFS you are able to use this template within a build definition. This template can be used by selecting show details in the process tab of a build definition and then selecting “New” to browse to the location were you have saved the build template within TFS.

image

Underneath the template selection you can see the parameters of the build template.

image

The categories 1,2,3,4,5 are the default categories. The Release category is the category that can be used to define the parameters regarding “Release Management”. The “Extra Files” category this is the category for our added argument.

In the next couple of post we will see how this build template will be used to start off a “Release” within “Release Management” order to start a SharePoint deployment.