Sunday, 6 September 2015

Integrating TFS with Jenkins

Hi Everyone,

As you all know I'm no great fan of TFS. Since I last talked about TFS things have improved somewhat.

Let me tell you a brief story.

PART 1

Two weeks ago I was doing a very quick engagement for a utility company, mostly to help out a friend more than anything. The engagement was only for three days. As they had no CI capability I set up a Jenkins box and tried to integrate with the Bonobo Git server on the same box. Jenkins failed check it out the code...we think because certificates needed to be set up. Due to time constraints we got approval to move the code to a private GitHub repo. Problem solved.

PART 2

Just this week, at my latest engagement (in the same building I'd just left 3 weeks earlier but that's another story!), I was confronted with a TFS server and a request to set up a CI build. I recommended Jenkins and Git. I expected they would take more convincing to move away from TFS as a build server, however fortunately they did their own research and came around to my thinking that TFS as a build server is just not as good as Jenkins. The difficult part was that private GitHub repositories would not be allowed in this corporate environment. (This corporate is very behind the times!)

PART 3

We struggled for a couple of days to setup a git repo we could control in the (overly locked down) dev environment that we had been given. In the end we abandoned this endeavor...we tried all manner of things, even a git backed repository in TFS 2013...just too hard.

I thought I'd take another look at the TFS plugin for Jenkins and was very pleased to see that it has recently been through a major rewrite. Version 4.0 of the plugin was released on August 27th, 2015....and it works!

The trick is to get the settings "just so".

  1. In the job config select the Team Foundation Server option from the Source Management section.
  2. In the Server URL field enter https://<tfs-server-name>:<port>/tfs/<collection-name>
  3. In the Project path field enter $/path/to/root/of/my/solution
  4. In the User name field enter the user name that has access to TFS
  5. In the User password field enter the password associated with the user name

I didn't enter anything else.

Points to note:

  • The Server URL has to be html escaped. So, for instance my <collection-name> had spaces in it, so My Collection Name becomes My%20Collection%20Name. If your <tfs-server-name> or <collection-name> has other special characters they will also have to be correctly escaped.
  • The User name doesn't have to be an email address. In my case it wasn't.

If you don't get the above settings correct (I initially didn't know I had to include the collection name), you'll probably get an error such that it can't find a SOAP endpoint.

Get it correct, however and BAM! your Jenkins workspace will be populated with your source code.

Now it is easy integrate Jenkins with TFS such that you can get the code out of TFS and work with it in a Jenkins build.

Hopefully this has been helpful to someone out there. Let me know in the comments. I always like to hear your feedback.

Till next time...

5 comments:

  1. BAM! indeed. Just had this happen after an upgrade to TFS 2015 and we mistakenly thought there was a problem with the Jenkins TFS plugin itself.

    Thank you for running this issue down, bud. Really thought I was going to have to write a script to pull code down into a shared drive or something goofy :)

    ReplyDelete
  2. Thanks Michael. Always great to hear feedback. Glad it helped.

    ReplyDelete
  3. Glad to be reading this!
    I just got it to work too. Say - do you have any experience / example of getting TFS to work with the scripted Pipelines in Jenkins?

    ReplyDelete
    Replies
    1. Hi Carl,

      Thank you. I am still feeling my way with TFS and Jenkins.

      I am yet to use scripted pipelines. I'll be writing another post over the weekend that talks about the setup we have evolved to: being able to deploy any labelled version to a target environment with a parameter oars build.

      Delete
    2. Splendid! That would be an interesting read too.
      Big thanks!

      Delete