Wednesday, February 25, 2009

Hudson for .NET Projects

I’ve been working on some SharePoint projects recently, and I wanted to implement Continuous Integration(CI).  Unfortunately, I did not find much information when I was researching CI for SharePoint projects.  My company traditionally uses CruiseControl.NET for its standard .NET projects; however, CC.NET seemed to require a good bit of configuration to get started.  I was looking for something I could spin up rather quickly.  I had heard Java folks raving about Hudson's ease of use out of the box, so I wanted to see if the same held true for .NET and SharePoint projects.  I was amazed at how simple it was.

Since I didn’t see many people in the blogosphere talking about Hudson with .NET (and even fewer talking about Hudson with SharePoint).  I thought I would give a very basic tutorial on the .NET set-up for Hudson.  NOTE: Hudson is a Java .war file, so it requires Java 1.5 or later to be on the machine.

Step One – Download Hudson from https://hudson.dev.java.net/

Step Two – If Hudson downloaded as a .zip file, rename it to Hudson.war

Step Three – Run Hudson from the command line, by executing the following line:

java –jar hudson.war

Step Four – Now that Hudson is running, pull it up in the browser.  By default, it will be running at http://localhost:8080/

Step Five – Hudson does a lot of things out of the box, mostly centered around Java tools.  So to get .NET projects up and running, we’re going to need to download some plugins.  Hudson makes this incredibly easy.  From the home page, click on the “Manage Hudson” link.  Then, on the manage screen, click on the “Manage Plugins” link.

On the Manage Plugins page, select the "Available" tab and select the tools required for your build.  As you can see in the screenshot below, there are plugins for MSBuild and MSTest, but I have selected NAnt and NUnit as my tools of choice.  There is a TFS plugin, but I haven’t used it yet.  I am currently using Subversion on my projects

HudsonPlugins

Once the plugins have been installed, you’ll need to restart Hudson. 

Step Six – From the home page, click on the “Manage Hudson” link.  Then click on the “Configure System” link.  This screen will allow you to configure the email server and the default Nant installation.  

 HudsonConfigureNantEmail

Now you’re set for adding projects.  And now for the easy part…

Step Seven – Add a new job.  Click on the “New Job” link to start the wizard for adding new jobs.  Enter a name for the job and make sure you have selected “Build a free-style software project”

HudsonAddJob

The next page of the wizard allows you to set up the details of the job (where to pull the code from, how to trigger the build, which build scripts to execute,  how to publish results, and who should receive email notifications).  Note: I did find a limitation when working with NAnt build scripts.  A job will only execute one NAnt script.  This isn’t too bad of a limitation, you will just need to aggregate some targets in a single target of your build file.

HudsonConfigureJob

Conclusion

Comparing this with other CI tools I’ve used in the past, Hudson is the easiest and has the fewest limitations.  I have used tools that required heavy custom xml configuration, had severe limitations (would not poll source control for changes), or were only built for one platform.  Hudson walks you through all necessary configuration on its UI, without being a hindrance to getting things done.  It is very flexible in what it can do, and has amazing support with a variety of plugins.  Finally, it is not just set up for one platform.  Although it requires Java to execute, there is support for a variety of platforms and languages.

10 comments:

  1. I just seen your post about hudson, and I am a newbie with this since I am starting this out today.

    I have some gray area, specifically on the location of the build file & solution. example :
    hudson server:
    c:\hudson\repository\mysolution (where .build & solution file located)

    Is this mean that every time a made a changes & commit it using SVN, I have to copy my local copy of a solution to a designated folder on the hudson server?


    thanks,

    No Body

    ReplyDelete
  2. You should be checking in your build and solution files to SVN. Then you could point Hudson to the build. I see that I kind of left that step out. So, from your example, if your build file is c:\hudson\repository\mysolution\project.build, you should check in the mysolution directory to SVN. Then you could just reference the NANT build file as project.build

    I hope this helps.

    ReplyDelete
  3. Thanks for the re:, kinda lost on check-in/commit your build (my solution).

    I only knew how to commit my source code to the SVN. but not my solution build.

    can you site some step by step sample base on your Sharepoint_demo, "I see that I kind of left that setp out"

    thanks,

    No body

    ReplyDelete
  4. And another thing, how do I tell Hudson that my NAnt.exe is not in the \bin folder?

    it's keep looking for this path:

    C:\myProjects\web2009\tools\nant\bin\NAnt.exe //doesn't exist

    but in the reality I setup it, in here:

    C:\myProjects\web2009\tools\nant\NAnt.exe // the correct path

    ReplyDelete
  5. I've seen that problem before. To get around it, you can just create a bin folder and move your exe into it. Hudson expects NAnt to be set up under a bin folder.

    As for your other question, I don't know if you should need step by step instructions. I commit the entire solution to svn. This includes the .build file. So when I specify it in Hudson, I just give the relative path to the build file. Since it is directly in my solution folder (I use it to build the entire solution), I just need to put the name of the build file in the NAnt build file text box.

    ReplyDelete
  6. Does hudson supports .net framework 4 and visual studio 2010?. I'm able to build the project using above tools. But hudson is not showing violations and test results. The xml fiels are getting generated. Any idea?

    ReplyDelete
  7. More than a year has passed since you wrote the Hudson article. Any further thoughts? Is Hudson still your choice? Have you compared it to Microsoft's offerings in 2010? What about CruiseControl.NET GUIs? Or that package that has gotten so much good press: TeamCity. Not looking for a full article. Just some bullet-point observations.
    I'm a .NET guy in a Java group that really has its act together for CI. The group use Jira, Subversion, Bamboo, Maven, Wagon, Nexus, Clover, GlassFish. We're taken over a .NET app (C# ASP.NET) and want to get CI going with that app, as well. The idea is to
    (1) Hold to the core CI values the team has implemented,
    (2) Be as consistent as possible with the tool set the team has currently, while still being realistic about what works for .NET,
    (3) Give a preference for tools associated with the Java community because members of the team know Java and open source tool, even if they are not using them currently
    (4) Don't get too weird about it -- i.e., if TFS really does work best and is reasonably priced, then use it.

    What are your thoughts?

    ReplyDelete
  8. I haven't really been evaluating new tools recently. Hudson still does the job for me. I wouldn't go with TFS just because you're working in .NET. I feel like TFS tries to do a lot of things, and doesn't do any of them very well. The Hudson community is very strong and growing. I think it would be a good fit for your team and ease their transition from Java.

    ReplyDelete
  9. I'm new to Hudson, evaluating it as a CI tool.
    My installation is hudson 1.398, jdk 6u24, nant plugin 1.4.1 on Windows Server 2003 (same issue on Windows XP); my nant version is NAnt 0.91 Alpha 2.

    My problem is that on the Hudson Manage Plugins page, the nant plugin is listed as being installed, however, it does not appear on the Configure System link, and so I can't set up a job to use nant.

    I've searched extensively and can't find any clues to help resolve this; any suggestions gratefully appreciated.

    ReplyDelete
  10. Sorry for the late reply. I just checked an install of Jenkins 1.405, and the Nant Builder section is on the Configure System page. One thing that might throw you off is that it is collapsed by default. Sorry I'm not much more help than this, but if you have the plug-in installed, you should see 'Nant Builder' on the configure page.

    ReplyDelete