Jenkins: Configure CI with TFS, NSUnit – Build, Package

Today I want to tell about the way to create a C.I. with Package and Deploy with Jenkins. Jenkins is “an extendable open source continuous integration server”. There are a lot of good articles on internet which explain what is jenkins and the base configuration

but it is difficult to find tutorial or article that discuss about NSUnit, configuration and Packages together. First of all we need to create a a simple MSBuild script with all steps that we need.
In this first post, we can discus about the msbuild script. Now we prepare a script to put inside our jenkins:

1 – Clean Solution

	<Solution Include="${RootPath}\src\TestProjectComplete.sln"/>
<Target Name="Clean">
	<Message Importance="high" Text="Cleaning folders"/>
	<RemoveDir Directories="$(BinPathUnitTests)" />
	<!-- Clean the source code projects -->
	<MSBuild Projects="@(ProjectFiles)"
	Properties="Configuration=$(Configuration)" />

2 – Get packages from Nuget

<!-- The LoadNuGetPackages Target -->
	<NuGetPackageConfigs Include="E:\workspace\TestProjectComplete\src\**\packages.config" />
<Target Name="LoadNuGetPackages">
	<Message Importance="high" Text="Retrieving packages for %(NuGetPackageConfigs.Identity)" />
	<Exec Command="&quot;$(SrcPath)\.nuget\nuget&quot; install &quot;%(NuGetPackageConfigs.Identity)&quot; -o &quot;$(SrcPath)\packages&quot;" />

3 – Build projects

<Target Name="Compile">
	<Message Importance="high" Text="Compiling projects"/>
	<MakeDir Directories="$(BinPathUnitTests)" />
	<MSBuild Projects="$(SrcPath)\TestProjectComplete\TestProjectComplete.csproj" Properties="Configuration=$(Configuration);Platform=$(Platform)" />

4 – Run unit test

<!-- Running Test -->
<Target Name="NUnit">
		<TestAssembly Include="$(BinPathUnitTests)\*.test.dll" />
	<Message Text="NUnit is running on: @(TestAssembly)" />
	<Nunit ToolPath="$(NUnit-ToolPath)" Assemblies="@(TestAssembly)" OutputXmlFile="$(BinPathUnitTests)\test-results.xml"/>

5 – Packages

<Target Name="Package">
	<MakeDir Directories="$(Publish)" />		
	<MSBuild Projects="$(SrcPath)\TestProjectComplete\TestProjectComplete.csproj"
		Targets="ResolveReferences;_CopyWebApplication" />

In my Github repository you can find the msbuild script (here). The next post we discuss how to configure jenkins to use this script.

Changing local path in team foundation server

application-lifecycle-managementIf you want to change the local path for the working directory of the Team Foundation Server (TFS), you need to go to File -> Source Control -> Workspaces, then select your workspace (it should match your computer name) and click Edit.

In the next dialog change the mapping for the root TFS node to the new location on your hard drive.

Important! You need to perform a “Get” on the whole TFS tree to update project associations.