Saturday, January 12, 2013

Create a Mono C# Buildserver using Jenkins and GitHub

Saturday, January 12, 2013 Posted by Andre Broers , , , , , , , , ,
My favourite development environment is Visual Studio. All my serverside code I develop in Visual Studio on my workstation. I have a homeserver with VMware ESXi where I run several linux instances. All my webprojects I host from this instances. To keep the cost low I run them on Linux. Same with my Continuous Integration setup. I use the Linux - Jenkins - Mono - Github combination to build my projects. In this post I will demo how to create this setup.

Install Linux Ubuntu Server 12.04

First thing to do is install a Linux server and call it build01. It needs a minimum of 1gb of memory (because to the java stuff :-)) Look at my previous blog post how to install ubuntu.

Install Git

sudo apt-get update
sudo apt-get install git

Install Mono

sudo apt-get update
sudo apt-get install mono-complete

Install Jenkins

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins


Now it is time to start jenkins for the first time. Open a browser and browse to http://build01:8080


Configure Jenkins

Now go to Manage Jenkins and select Manage Plugins. We need to install the MSBuild Plugin. Goto the tab Available and type msbuild in the Filter box. Select the plugin and click Download now and install after restart.


Install the GitHub Plugin the same way. This will also install two other dependent plugins.
After installing enable all the plugins in the same screen. This is an important step.

Now goto Manage Jenkins - Configure System. Here we configure de MSBuild plugin and add a new MSBuild installation:



This is the mono msbuild tool called xbuild. Now the msbuild step will use this build tool to build visual studio sollutions or other msbuild project files. Remember this tool is not completely compatible with msbuild from Microsoft, but I can build my Console Applications and Libraries with it. I use NancyFx for my webapplications and these projects build fine also.

Now it's time to create a new project in jenkins. I have a simple solution with a consoleapp in it that copies my photos in the right folder using exif information in github at: https://github.com/broersa/photorename.git .
This project doesn't use downloading nuget packages at build time, but this is also supported. xbuild will run nuget.exe and download nuget packages. It all works on mono.

At the jenkins dashboard click New Job. Name the job and select Build a free style job project and click Ok.


In the next screen enter the github project url in  the GitHub project box and select Git at the Source Code Management section. Fill in the Repository URL and scroll down to the build steps.


Now click the second Advanced button to open the Git advanced options.


 Now a whole of options open and we need to select the option skip internal tag.



Goto Build section and click Add build step. Select an MSBuild step.



Now select the mono installation we configured in the previous steps and fill in the solution of the project to build.


Click Save to save the project. Now we can build the C# Mono Visual Studio solution on Linux.
From the dashboard click our project and select Build Now. The project is now building.


We see a succesfull build and can now view the log to see what jenkins did to build the solution:

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/photorename/workspace
Checkout:workspace / /var/lib/jenkins/jobs/photorename/workspace - hudson.remoting.LocalChannel@74ed41f8
Using strategy: Default
Cloning the remote Git repository
Cloning repository https://github.com/broersa/photorename.git
git --version
git version 1.7.9.5
Fetching upstream changes from https://github.com/broersa/photorename.git
Seen branch in repository origin/HEAD
Seen branch in repository origin/master
Commencing build of Revision 980fc0b10f9dc29dd6b1f8e00037534dca240f01 (origin/HEAD, origin/master)
Checking out Revision 980fc0b10f9dc29dd6b1f8e00037534dca240f01 (origin/HEAD, origin/master)
No change to record in branch origin/HEAD
No change to record in branch origin/master
Path To MSBuild.exe: /usr/lib/mono/4.0/xbuild.exe
Executing the command /usr/lib/mono/4.0/xbuild.exe PhotoRename.sln from /var/lib/jenkins/jobs/photorename/workspace
[workspace] $ /usr/lib/mono/4.0/xbuild.exe PhotoRename.sln
XBuild Engine Version 2.10.8.1
Mono, Version 2.10.8.1
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.

Build started 1/12/2013 5:36:22 PM.
__________________________________________________
Project "/var/lib/jenkins/jobs/photorename/workspace/PhotoRename.sln" (default target(s)):
 Target ValidateSolutionConfiguration:
  Building solution configuration "Debug|x86".
 Target Build:
  Project "/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/PhotoRename.csproj" (default target(s)):
   Target PrepareForBuild:
    Configuration: Debug Platform: x86
    Created directory "bin/Debug/"
    Created directory "obj/x86/Debug/"
   Target GetReferenceAssemblyPaths:
/usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Unable to find framework corresponding to the target framework moniker '.NETFramework,Version=v4.0,Profile=Client'. Framework assembly references will be resolved from the GAC, which might not be the intended behavior.
   Target ResolveAssemblyReferences:
/usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' not resolved
    For searchpath /var/lib/jenkins/jobs/photorename/workspace/packages/ExifLib.1.2.4436.20486/lib/net20
    Considered '/var/lib/jenkins/jobs/photorename/workspace/packages/ExifLib.1.2.4436.20486/lib/net20/mscorlib' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/packages/ExifLib.1.2.4436.20486/lib/net20/mscorlib.exe' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/packages/ExifLib.1.2.4436.20486/lib/net20/mscorlib.dll' as a file, but the file does not exist
    For searchpath {CandidateAssemblyFiles}
    Warning: {CandidateAssemblyFiles} not supported currently
    For searchpath {HintPathFromItem}
    HintPath attribute not found
    For searchpath {TargetFrameworkDirectory}
    For searchpath {PkgConfig}
    Considered mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, but could not find in any pkg-config files.
    For searchpath {GAC}
    Considered mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, but could not find in the GAC.
    For searchpath {RawFileName}
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' as a file, but the file does not exist
    For searchpath bin/Debug/
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/mscorlib' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/mscorlib.exe' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/mscorlib.dll' as a file, but the file does not exist
/usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' not resolved
    For searchpath /var/lib/jenkins/jobs/photorename/workspace/packages/NDesk.Options.0.2.1/lib
    Considered '/var/lib/jenkins/jobs/photorename/workspace/packages/NDesk.Options.0.2.1/lib/mscorlib' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/packages/NDesk.Options.0.2.1/lib/mscorlib.exe' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/packages/NDesk.Options.0.2.1/lib/mscorlib.dll' as a file, but the file does not exist
    For searchpath {CandidateAssemblyFiles}
    Warning: {CandidateAssemblyFiles} not supported currently
    For searchpath {HintPathFromItem}
    HintPath attribute not found
    For searchpath {TargetFrameworkDirectory}
    For searchpath {PkgConfig}
    Considered mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, but could not find in any pkg-config files.
    For searchpath {GAC}
    Considered mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, but could not find in the GAC.
    For searchpath {RawFileName}
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' as a file, but the file does not exist
    For searchpath bin/Debug/
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/mscorlib' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/mscorlib.exe' as a file, but the file does not exist
    Considered '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/mscorlib.dll' as a file, but the file does not exist
/usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Found a conflict between : 'System' and 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using 'System' reference.
   Target CopyFilesMarkedCopyLocal:
    Copying file from '/var/lib/jenkins/jobs/photorename/workspace/packages/ExifLib.1.2.4436.20486/lib/net20/ExifLib.dll' to '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/ExifLib.dll'
    Copying file from '/var/lib/jenkins/jobs/photorename/workspace/packages/NDesk.Options.0.2.1/lib/NDesk.Options.dll' to '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/NDesk.Options.dll'
   Target GenerateSatelliteAssemblies:
   No input files were specified for target GenerateSatelliteAssemblies, skipping.
   Target CoreCompile:
    Tool /usr/bin/dmcs execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/x86/Debug/PhotoRename.exe Program.cs Properties/AssemblyInfo.cs /target:exe /define:"DEBUG;TRACE" /platform:x86 /reference:../packages/ExifLib.1.2.4436.20486/lib/net20/ExifLib.dll /reference:../packages/NDesk.Options.0.2.1/lib/NDesk.Options.dll /reference:/usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll /reference:/usr/lib/mono/gac/System.Xml.Linq/4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll /reference:/usr/lib/mono/gac/System.Data.DataSetExtensions/4.0.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll /reference:/usr/lib/mono/gac/Microsoft.CSharp/4.0.0.0__b03f5f7f11d50a3a/Microsoft.CSharp.dll /reference:/usr/lib/mono/gac/System.Data/4.0.0.0__b77a5c561934e089/System.Data.dll /reference:/usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll /reference:/usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll /warn:4
Program.cs(18,18): warning CS0219: The variable `verbose' is assigned but its value is never used
Program.cs(25,26): warning CS0219: The variable `extra' is assigned but its value is never used
   Target DeployOutputFiles:
    Copying file from '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/obj/x86/Debug/PhotoRename.exe.mdb' to '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/PhotoRename.exe.mdb'
    Copying file from '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/obj/x86/Debug/PhotoRename.exe' to '/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/bin/Debug/PhotoRename.exe'
  Done building project "/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/PhotoRename.csproj".
Done building project "/var/lib/jenkins/jobs/photorename/workspace/PhotoRename.sln".

Build succeeded.

Warnings:

/var/lib/jenkins/jobs/photorename/workspace/PhotoRename.sln (default targets) ->
(Build target) ->
/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/PhotoRename.csproj (default targets) ->
/usr/lib/mono/4.0/Microsoft.Common.targets (GetReferenceAssemblyPaths target) ->

 /usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Unable to find framework corresponding to the target framework moniker '.NETFramework,Version=v4.0,Profile=Client'. Framework assembly references will be resolved from the GAC, which might not be the intended behavior.

/var/lib/jenkins/jobs/photorename/workspace/PhotoRename.sln (default targets) ->
(Build target) ->
/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/PhotoRename.csproj (default targets) ->
/usr/lib/mono/4.0/Microsoft.Common.targets (ResolveAssemblyReferences target) ->

 /usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' not resolved
 /usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' not resolved
 /usr/lib/mono/4.0/Microsoft.Common.targets:  warning : Found a conflict between : 'System' and 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using 'System' reference.

/var/lib/jenkins/jobs/photorename/workspace/PhotoRename.sln (default targets) ->
(Build target) ->
/var/lib/jenkins/jobs/photorename/workspace/PhotoRename/PhotoRename.csproj (default targets) ->
/usr/lib/mono/4.0/Microsoft.CSharp.targets (CoreCompile target) ->

 Program.cs(18,18): warning CS0219: The variable `verbose' is assigned but its value is never used
 Program.cs(25,26): warning CS0219: The variable `extra' is assigned but its value is never used

  6 Warning(s)
  0 Error(s)

Time Elapsed 00:00:01.1354710
Finished: SUCCESS