Archive for the ‘.NET’ Category
Jenkins, Windows and Git

Update: managed to clone Git repository via Git/SSH.
Recently I have successfully set up Jenkins CI (called Hudson CI until recently) in Windows 2008 virtual machine. It was not hard once I figured all the stuff that needs to be done, but it was far from trivial. At one point I almost gave up on Jenkins because I could not get it to clone Git repository. But with help from Adam Goucher I was able to get it working. More about that later in the post.
Since then I have been reading Jenkins: The Definitive Guide book and playing with Jenkins in the virtual machine. (By the way, there is free pdf version of the book, and $34.99-$49.49 print and ebook versions.) I am almost done with the book and I plan to write a short review after I read it.
Continuous integration server is not really useful when it is in a virtual machine on my laptop. Neither my laptop nor virtual machine work 24/7, and the point of continuous integration server is exactly that. Running 24/7.
So, today the time was right to get Jenkins working on a server. I am writing this to have a reminder how to set up Jenkins and Git on Windows, so I do not have to repeat setup nightmare ever again.
Jenkins
Jenkins installation is pretty simple and it is covered pretty well, both on the Jenkins web site and in the book. I have installed it as Windows native package, and I made my first mistake there. By default, Jenkins installs in C:\Program Files\Jenkins\ (on 32-bit Windows) or C:\Program Files (x86)\Jenkins\ (on 64-bit). I am really surprised that they do that. I had so many problems with Jenkins because it was installed in a folder with spaces in name. Install Jenkins in C:\Jenkins. (Ruby installed is smarter. It installs by default in C:\Ruby. But that is another story.)
After the installation, Jenkins will open your default web browser and go to it’s home page, http://localhost:8080/. Another surprise. Since the server is in Switzerland, Internet Explorer language was set to French, and Jenkins was in French. Since I do not know any French, I had to change it to English. Go to Internet Explorer > Tools > Internet Options > General > Languages to change the default language.
Jenkins Build Job
With everything back to a language I know, it is the time to create a new job. Click link New Job. Another warning. Do not use spaces in job names. Jenkins creates folders for each job in C:\Jenkins\jobs, and if you name the job build job, it will create C:\Jenkins\jobs\build job folder. You already know spaces in folder names are a bad idea. Call your job something like build. After entering job name, select Build a free-style software project and click OK. Configure job page opens. Just click Save for now. That is it. You have created a job. It does not do anything for now, but we will get there. By the way, take a look at C:\Jenkins\jobs\build. There is just a config.xml file there for the moment. Do not change it.
Jenkins Git Plugin
The next thing we have to do is to get some source code on the machine. If you did not navigate away from the job page (http://localhost:8080/job/build/), click Configure link. You will notice that Git is not listed under Source Code Management at job configuration page. You have to install a plugin.
Go to Jenkins home page (it is http://localhost:8080/, to get there click Jenkins link in the top-left part of the page) and then click Manage Jenkins > Manage Plugins > Available. Check Git Plugin checkbox and click Install. Check Restart Jenkins when installation is complete and no jobs are running checkbox and wait for Jenkins to restart. This restarting Jenkins step is the strangest part. I am never sure when it has restarted. When I get bored waiting, I just go to Jenkins home page and it usually just works.
Go back to job configuration page, and you will see Git listed under Source Code Management. Click it and enter URL of repository. I will use Git read only URL from watirbook project. So, I will use git://github.com/zeljkofilipin/watirbook.git. Click button Save.
If you have Git installed, you are ready for the first build. It will actually just clone the repository, but it is a start. Click Build Now link. In Build History you will notice the first build. It failed for me. To debug the problem, click the build link (something like Oct 20, 2011 7:57:19 PM) and then Console Output. For me it said Cannot run program "git.exe": CreateProcess error=2, The system cannot find the file specified.
Git
Time to install Git. Download it from Git home page. On download page select Full installer for official Git for Windows. I did not want to install it in Program Files folder, so I have installed it in C:\Git.
Try building the job again. It failed for me again, with the same error message. To fix the problem, you have to let Jenkins know where to find Git. Go to Jenkins configuration (Jenkins > Manage Jenkins) and click Configure System (Do not confuse it with job configuration at job > Configure.)
Under Path to Git executable you will see something like this: There's no such executable git.exe in PATH.... Replace git.exe with C:\Git\cmd\git.cmd and click button Save.
Do not replace git.exe with C:\Git\bin\git.exe. Cloning repositories via Git/SSH will not work. Do not ask. I have spent an entire day on that.
Go back to Configure System page, and if you did everything right, there should not be any error message under Path to Git executable. Leave the page open for 5-10 seconds. I have noticed that sometimes the error message does not appear immediately.
Go back to the job and build it again. It should work now. Finally. You will notice blue ball next to the newest build (instead of red ball for failing builds). I am not sure why they use blue for passing builds when green is a convention. But, there is a fix for that. Install Green Balls plugin (Jenkins > Manage Jenkins > Manage Plugins > Available > Green Balls> Install > Restart Jenkins.) If you do not see the green balls, click ctrl+f5 to refresh the page.
The Fun Starts Here
The fun starts if you want to clone Git repository that is not public. Change repository URL to git@github.com:zeljkofilipin/watirbook.git. Build again. Console Output page was stuck for me at Cloning repository origin for a long time. You can cancel the build by clicking red x button in the top-right corner of the Console Output page. You will get the whole error message then. It said ERROR: Could not clone repository. I am not surprised since I did not even set up this machine for Git/SSH authentication.
Go to Start > Git GUI > Help > Show SSH key > Generate Key. When it asks for passphrase, leave it empty. Copy the key to clipboard and close Git GUI.
At GitHub go to Account Settings > SSH Public Keys > Add another public key. Enter something in Title, paste the key in Key and click Add key.
(If you are using Unfuddle go to Personal Settings > Public Keys > New Public Key…. Enter something in Title, paste the key in Value and click Add.)
Sometimes it takes a couple of minutes for the key to become valid.
Test the Git setup by opening Command Prompt and cloning the repository there. So, go to your Desktop folder in Command Prompt and clone the repository. Example for my watirbook repository would be:
git clone git@github.com:zeljkofilipin/watirbook.git
If Git complains that The authenticity of host can't be established, type yes when it asks Are you sure you want to continue connecting (yes/no).
Everything worked just fine from the command line. Now I have Git repository at my desktop. But I want it in Jenkins. Try to build the job from Jenkins again. It still does not work. The same error message as the last time. This is the part where I almost gave up. The problem is that you have set Git/SSH authentication to work for your user (zfilipin in my case). But Jenkins is using Git as Local System Account instead of using it as zfilipin.
To fix this go to Start > Services > Jenkins > right click > Properties > Log On > This account, enter username and password and click OK. Restart Jenkins service (right click > Restart). When I was trying this in virtual machine, my user did not have any password, so this did not work. The workaround is to create a password for the user.
Try building the job again. Everything should work just fine.
Ruby Mail and benchmark.rb on CRuby, JRuby, IronRuby and RubyInstaller
Update: Steve suggested I should try the script also with RubyInstaller, and I did it.
This blog post is update of my recent Ruby Mail on CRuby, JRuby and IronRuby post. Mikel and Jimmy have commented on the post saying I did a poor job, and I would agree. I decided to do a better job this time. Please let me know if measurements can be further improved.
So, I have an e-mail file called 1.eml:
Date: Thu, 24 Dec 2009 14:37:34 Central European Standard Time From: from@test.com To: to@test.com Message-ID: <4b336e9e762a0_a1014263a4689d3@2003-ie7.mail> Subject: This is a test email Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII"; Content-Transfer-Encoding: 7bit Some text for mail body
The First Try
This is the test from the first post. (RubyInstaller was not included in the first post.) It is included here so all code and numbers are at the same page, I guess it is easier to compare that way. Read the file, display subject and total time elapsed (in seconds).
time = Time.now
require "rubygems"
require "mail"
mail = Mail.read("1.eml")
puts mail.subject.to_s
puts Time.now - time
Executed the script three times for each Ruby implementation. RubyInstaller the fastest, CRuby and JRuby were similar in speed, IronRuby was way slower.
| Test Run | 1 | 2 | 3 |
|---|---|---|---|
| CRuby | 2.594 | 2.109 | 2.11 |
| JRuby | 3.0 | 2.016 | 2.0 |
| IronRuby | 9.8125 | 7.796875 | 7.6875 |
| RubyInstaller | 1.21875 | 1.203125 | 1.203125 |
| Test Run | 1 | 2 | 3 |
|---|---|---|---|
| CRuby | 0.015 | 0.016 | 0.0 |
| JRuby | 0.047 | 0.047 | 0.047 |
| IronRuby | 0.5 | 0.46875 | 0.484375 |
| RubyInstaller | 0.0 | 0.0 | 0.0 |
| Test Run | user | system | total | real |
|---|---|---|---|---|
| CRuby | 11.000000 | 0.657000 | 11.657000 | 13.485000 |
| JRuby | 6.187000 | 0.000000 | 6.187000 | 6.187000 |
| IronRuby | 69.984375 | 7.140625 | 77.125000 | 60.656250 |
| RubyInstaller | 7.297000 | 0.766000 | 8.063000 | 9.953125 |
Environment
Tests were run in VMware Fusion 2.0.6 virtual machine, 512 MB RAM, Microsoft Windows Sever 2003 R2 (Standard Edition, Service pack 2).
Host machine is MacBook Pro, 2.4 GHz Intel Core 2 Duo, Mac OS X 10.6.2, 4 GB RAM.
>ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] >jruby -v jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) Client VM 1.6.0_10) [x86-java] >ir -v IronRuby 0.9.3.0 on .NET 2.0.0.0 >ruby -v ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]
Mail version 1.3.4 on all platforms.
ASP.NET – Install Everything You Need
Recently I started to play with ASP.NET. I found asp.net, The Official Microsoft ASP.NET 2.0 Site. The first thing you have to do is to install required software.
In my opinion, they made the installation to complicated for total beginner. There are too many choices. I wish they had something like Instant Rails. I lost some time figuring it out, so I decided to share my experience. Maybe it will help somebody. If you have comments, improvements, or if I did something wrong, please leave a comment.
At asp.net home page there is link GET ASP.NET. It leads to Essential Downloads page. There they say you need Microsoft .NET Framework Version 2.0 (framework) and Visual Web Developer 2005 Express Edition (IDE). Language version was easy to choose (English), but do I need Framework or SDK version of framework? That was also easily answered when I saw
If you are new to web development, select the Framework download.
The truth is that you do not have to download framework. It will automatically be downloaded when you download IDE. I selected English version of IDE.
Download page opens with four easy steps.
The first step was to check if my computer meets the System Requirements. It did. That was easy enough. Also, uninstall any previous versions of SQL Server 2005, IDE and framework. I did not have any installed.
The second step is to download IDE. But, there is just to many options. Six. I just want to download an IDE for language I do not know nothing about, and they make me choose. I just knew that my developer uses ASP.NET and C#. And at that page there are Visual Web Developer and Visual C# IDE-s. Later I found out that I do not need Visual C#. (But after I downloaded and installed it. Do not make the same mistake.)
After download (Visual Web Developer is what you need), execute downloaded file. Of course, you have to be logged in as administrator. At the third screen of installation wizard there is option to also download and install Microsoft MSDN 2005 Express Edition and Microsoft SQL Server 2005 Express Edition x86. You need only SQL Server. At the next screen I noticed that Microsoft .NET Framework 2.0 will also be installed.
The third step is to download updates and additional components. You can install additional components later if you want to, no need to do it now. You do not have to download updates if you perform Microsoft Update after installation. That is what I did. There was two updates for .NET Framework and one for Visual Studio. I just wonder why they just do not offer the newest version of IDE and .NET framework, but instead you have to download an old version and than update it.
The fourth step is registration. You have 30 days, so there is no rush. But beware (from FAQ):
Without a registration key, downloaded Editions will no longer work after 30 days.
So, all you have to do is to download Visual Web Developer, make sure that SQL Server is also downloaded (while installing IDE) and perform Microsoft Update after installation.
