When I was working for Medtelligent Inc. as a software developer a few months ago one of the things that really helped us to enhance the quality of the software we were building was presence of a good stack of project management tool, source control and continuous integration server for automated builds. That experience was good enough for me to bear in mind that I should try to use CI for every project that I’m responsible for. Recently I’d decided to setup a CI server for the company I’m currently work for as a project manager and since my experience with Hudson CI tool was good I decided to use this as well as GitHub as our source control server. It wasn’t completely straight forward to get it up and running but finally I could manage to get it working! Cause many of you may like to use my experience, I decided to share those tips I learnt during this job; so in this blog post I will try to demonstrate how to setup a CI server using Jenkins (a new fork of Hudson which is no longer active) and GitHub and MSBuild on a Windows Server.
First of all you need to download and install the latest version of Jenkins for Windows. Installing Jenkins on your Windows server wouldn’t be hard and will be done in a few minutes; just follow the steps provided in the installer and it will be installed on your machine easily.
Next step is installing required plugins inside Jenkins to interact with Git and GitHub. In order to do this select “Manage Jenkins” from the left side menu and then “Manage Plugins”; in the next page find Jenkins GIT Plugin and Jenkins MSBuild Plugin. Please note that you should have already installed Git on your Windows machine (if you don’t know how to do this read GitHub help) Don’t forget to restart Jenkins after installing these new plugins.
After installing those plugins you need to configure a few things:
- Copy .ssh folder and its content from your user folder (C:\Users\USERNAME\.ssh) into your Jenkins installation folder (typically C:\Program Files\Jenkins)
- Find Jenkins serice in your “Server Manager”, right click and choose Properties; then choose Log On tab and select “This account” and enter the Username and Password of the account you’ve logged in with and generated your public/private key:
- Restart Jenkins server by right clicking on its name and choosing “Restart”.
- Go to Manage Jenkins > Configure System and find Git section and set the values as shown below:
- Find MSBuild section and add required MSBuild installations and set the correct value to MSBuild.exe on your machine; you see the path for MSBuild for .NET Freamework 4.0 below:
- Go to SSH section and set the values for id_rsa key file as well as the private key available in that file as shown below:
I assume that you’ve already created required build scripts and put that inside a folder like “build” in your repository. The next step is creating a new job in Jenkins:
- Select “Create New Job”, enter a name for your job and select “Build a free-style software project:
- Click on Ok and go to the next step.
- Select Git as your Source Code Management and enter your Git repository address and branch name (leave the branch name field blank if you use master branch):
- Go to Build section and click on “Add build step” then choose Visual Studio option:
- Choose the MSBuild you created in Step 3 in configuration part and enter the relative path to your build script in your repository:
- Click on Save.
Now you’re ready to run your first build; if everything have been set correctly Jenkins will start to clone your repository from GitHub and then run your build script and if you have no error during the build process you will see the success message in Console Output of your current build: