DevOps Zone is brought to you in partnership with:

Punit, is Microsoft MVP and, has over 8+ years of professional experience working on designing Enterprise Applications on Microsoft Technology Stack especially for Financial Sector. He is an open-source contributor of CodeInject, Workflow Extractor and dI.Hook on CodePlex, has 6 applications in MarketPlace, and a freeware application 'myTracker' on Softpedia. He writes on various topics on his website & has spoken in various forums in UK and Singapore and is blogs on his website www.ganshani.com and social blog site www.codetails.com Punit is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

Build Automation Using Jenkins and TFS Version Control

04.28.2014
| 6069 views |
  • submit to reddit

I’ve used several version control systems for my source code and research projects.  Recently, I’ve consolidated them to TFS and Git. I have started using Visual Studio Online for my research work, CodePlex for my Open Source Frameworks and Tools and GitHub for my blog code.  Much of these decisions are driven based on the target audience and the nature of my work (code).  TFS, being an excellent ALM tool, offers more than just a version control system which can be particularly helpful when you are either having large teams to work with or have an open-source project whose build you would want to automate.  For my research development (that happens at home), I was keen on build automation for CInject project.

Visual Studio Online offers a complete package of Continuous Integration and Delivery to Azure Services but there is no such feature for TFS repositories of CodePlex.  For this case, I started evaluating other CI platforms like CruiseControl.NET, TeamCity and Jenkins.  I zeroed down on Jenkins for its ease of use, extremely light-weight deployment, my familiarity with it and zero-dollar cost in setting it up.

For this example, we would use CodePlex repository, but the method can be used with any on-premise TFS repository or even with Visual Studio Online

Downloading the latest version

A direct link to Windows Version of Jenkins is available here.  Installation of this will require administrative rights if you are doing it on Windows 7+, or Windows Server 2008+

Once the installation has been completed, you will have a service running in the Service Manager

image

If this service is running, you can access Jenkins console at:  http://localhost:8080/

Download TFS Plugin

Visit the Manage Plugin Page [Manage Jenkins > Manage Plugins > Available ] (shortcut) and search for Team Foundation Server plugin.  Click on the checkbox and press the button ‘Install without restart’

image

If your build machine/server has restricted access to the Internet, you will get an error downloading the file.

java.io.IOException: Failed to download from http://updates.jenkins-ci.org/download/plugins/tfs/3.1.1/tfs.hpi
    at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:781)
    at hudson.model.UpdateCenter$DownloadJob._run(UpdateCenter.java:1125)
    at hudson.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:1285)
    at hudson.model.UpdateCenter$DownloadJob.run(UpdateCenter.java:1103)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:104)
    at java.lang.Thread.run(Unknown Source)

In such cases, you need to download latest version of the plugin manually and copy it to

<<JenkinsInstallDirectory>>\plugins

image

You will need to restart Jenkins service if you had to install it manually.

Downloading Team Explorer Everywhere

If you are running this process on your desktop machine and you are a .NET developer, chances are that you would have Visual Studio 2012+ installed.  In such cases, you will have Team Foundation executables on your machine and also the path of TF executables will be mentioned in PATH system variable as well.

When TF executable path is not part of PATH system variable, you will have to configure Jenkins to look into the right directory (shortcut).  On my home laptop, I’ve configured it as,

image

If you are running this on your Windows Server which has only .NET framework installed, you will have to install TEE.  If you are running this on a Unix/Linux server, you will still need TEE.  This is a free executable from Microsoft and is very thin-client.  You can download and install it from here and setup the configuration as

    X:\Jenkins\TEE-CLC-12.0.1\TEE-CLC-12.0.1\tf.cmd

You would need to run tf eula on Command Prompt to accept the Agreement of Use and Terms and Conditions and press ‘y’ when it prompts.  Similar configuration needs to be done for Unix / Linux.  The same CMD file will work for Unix and Linux platforms.

Setting up TFS repository in Jenkins

Click on the New Job link on the left menu to create a new Build Profile (shortcut)

image

On the next screen, you can customize the configuration to enable concurrent builds, retry count, etc. But for this article, the focus would be to configure TFS workspace.  So to get the TFS configuration, visit your CodePlex framework page and get the TFS URL.  If you are configuring for a repository other than CodePlex, you can check the URL with your administrator

image

Copy the link to Jenkins as shown below and click on Apply

image

Now you can trigger Build for environment and it should build successfully. 

You can use this method with any TFS repository – On-premise as well as Visual Studio Online.  One thing worth noting here is – every TFS repository (here https://tfs.codeplex.com:443/tfs) has multiple collections (TFS01…. TFSxx) and each collection has projects.  The Server URL should include the name of the collection, whereas the Project path should be a relative path ($/…)to the actual project. 

Using CodePlex SVN Path with Jenkins

You can use SVN link to access the Codeplex repository as well.  Please note that if you are using a non-Codeplex repository, you may not have a SVN URL.

image

So you can opt for any method if you are using Jenkins for CodePlex and can setup Build Automation and Continuous Integration as well.

Hope this helps.

Published at DZone with permission of Punit Ganshani, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)