- Download and install the latest, native package, of the Jenkins Windows Installer from http://jenkins-ci.org (version used for this instruction: 1.595).
- Open up the Jenkins dashboard (localhost:8080).
- Go to "Manage Jenkins > Manage Plugins" and select the following plugins to install:
- Git Client
- Git Server
- Git Plugin
- BitBucket Plugin
- MSBuild Plugin
- Install Git Extensions from http://sourceforge.net/projects/gitextensions - Use all defaults.
- Install Git Bash from http://git-scm.com/download/win - During the installation select "Use Git from the Windows command Prompt" on the "Adjusting your Path environment page".
- I would suggest that you restart the machine at this point, this forces a restart of Jenkins (obviously). I suppose you could just restart Jenkins but hey....
- When Jenkins is installed on Windows, it runs the service a the local service account. This user will need to have .ssh setup to include the known_hosts and id_rsa files (See here on how to do this: https://gist.github.com/tehfoo/3708738#generate-rsa-key-pair-on-your-jenkins-server)
- Once these files have ben created, copy the entire .ssh directory to C:\Windows\SysWOW64\config\systemprofile. If you chose to run the service as a specific user, put the .ssh folder in the profile of that user (i.e. C:\Users\TheUser).
- Under global configuration for Jenkins, make sure to set the path to git as <InstallDirectory>\cmd\git.exe (NOT just git.exe)
- Go to the Jenkins dashboard and select "New Item".
- Put in a name that suits you and select "FreeStyle Project". Click Ok.
- On the configure page, under "Source Code Management", select "Git" and put in the SSH url of your BitBucket repo.
- Set the credentials to "none".
- Schedule your build ("Build Now") and your should see that succeed.
On to setting up the build:
- Firstly download NuGet.exe from https://nuget.codeplex.com/releases copy the exe to somewhere you'll find it.
- Install the latest version of the .Net framework and locate MSBuild.exe (take a look in the "framework" folder).
- Setup MSBuild on "Manage Jenkins > Configure System" by specifying a name and the full path to the MSBuild (noted in point 2).
- The purpose of NuGet here is to restore packages for the project and a bunch of parameters can be passed to nuget indicating package sources and the like. Personally, I prefer for all this to be setup in a config file instead. Take a look at the Nuget Command Line Reference if you'd like to use the command line options, but you can copy my settings (below), adjust for your need and store in a file named <Something>.config (remove the proxy settings if you don't need those). This config file can then be passed in using -ConfigFile. A note that passwords are hashed and will need to be set using the command line.
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="Alternative package source" value="http://packages.nuget.org/v1/FeedService.svc/" /> <add key="NuGet official package source" value="https://nuget.org/api/v2/" /> </packageSources> <activePackageSource> <add key="All" value="(Aggregate source)" /> </activePackageSource> <packageRestore> <!-- Allow NuGet to download missing packages --> <add key="enabled" value="True" /> <!-- Automatically check for missing packages during build in Visual Studio --> <add key="automatic" value="True" /> </packageRestore> <config> <add key="HTTP_PROXY" value="mycorpproxy" /> <add key="HTTP_PROXY.USER" value="domain\user" /> <add key="HTTP_PROXY.PASSWORD" value="the password as set by the command line option" /> </config> </configuration>
- On the build configuration of the project in Jenkins, add the following steps under "Build" (They should be in this order as well):
- "Execute Windows batch command" : <NuGet.exe Path>\NuGet.exe restore <name of sln/ csproj file of your project> -ConfigFile <Config Location>\<The config file from point 4>
- "Build a Visual Studio project or solution using MSBuild":
- MSBuild Version: Select the name you setup in point 3.
- MSBuild Build File: The name of your sln/csproj file.
- Command Line Arguments: http://msdn.microsoft.com/en-us/library/ms164311.aspx
And that’s it. If you’ve followed all the steps correctly, you’ll have a Jenkins instance setup and ready to build .Net applications. Click Build Now and off you go….
See these sites for reference:
- https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
- http://computercamp-cdwilson-us.tumblr.com/post/48589650930/jenkins-git-clone-via-ssh-on-windows-7-x64
- https://gist.github.com/tehfoo/3708738
- https://adrianliew.wordpress.com/2013/09/04/setting-up-jenkins-as-a-ci-server-for-net-3-54-04-5-projects-using-bitbucket-1-of-2/
- http://www.infoq.com/articles/MSBuild-1
- http://docs.nuget.org/docs/reference/command-line-reference
- http://docs.nuget.org/docs/reference/nuget-config-settings
- http://msdn.microsoft.com/en-us/library/ms164311.aspx
- http://blog.davidebbo.com/2011/03/using-nuget-without-committing-packages.html
- http://marcofranssen.nl/ci-with-jenkins-msbuild-nuget-and-git-part-2/
- http://automatetheplanet.com/2014/08/31/integrate-jenkins-msbuild-nuget/