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

http://marcofranssen.nl/ci-with-jenkins-msbuild-nuget-and-git-part-1/
http://codingcockerel.co.uk/2008/05/18/how-to-publish-a-web-site-with-msbuild/
http://jenkinsheaven.blogspot.ch/2013/08/automating-net-builds-its-not-all-about.html
http://yakiloo.com/jenkins-tfs-and-msbuild/

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

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

2 – Get packages from Nuget

<!-- The LoadNuGetPackages Target -->
<ItemGroup>
	<NuGetPackageConfigs Include="E:\workspace\TestProjectComplete\src\**\packages.config" />
</ItemGroup>
<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;" />
</Target>

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)" />
</Target>

4 – Run unit test

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

5 – Packages

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

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.