Continuous integration For a Xamarin App with Jenkins and deployments with Hockey App

In the previous post, we saw why Jenkins makes sense for Xamarin build, at least for now. If you have previously worked with continuous integration systems such as Team City, the steps in Jenkins will look familiar to you. The steps follow a logical flow. So, even if you're brand new to this, the learning curve is not that steep.

Jenkins supports a Master/Slave setup. If there is a master running on Windows, perhaps a Mac slave may do the trick. For simplicity, we are going to look at the master running on a Mac.

Jenkins provides a download for Mac and Windows at Jenkins .io. However, I am not going to recommend that. The installer creates a new shared user Jenkins on Mac. This complicates things if Jenkins needs to access anything from the Keychain of the logged in user(likely to be a service account or your own). So, if you are working with TFS Git or any Git repo over HTTPS, you are probably using OSXKeychain Helper or Microsoft's Credential Manager. Jenkins user simply can't access those easily. Creating another user just for Jenkins was not an option for me. We will now see how to get around this issue.

We are going to need Homebrew installed on the Mac. It is a package/application manager for Mac, Mac's Chocolatey from Windows world.
After installation, simply run the commands below:

brew Install Jenkins
brew services start Jenkins

This way Jenkins gets installed for the currently logged in user and the credentials/keychain access problem does not come up.

In order to make Jenkins site available from other machines, follow instructions below:

  • Open homebrew.mxcl.jenkins.plist located in/usr/local/Cellar/Jenkins/2.7 (your installed version could be different)
  • Change the -httpListenAddress=127.0.0.1 to 0.0.0.0
  • Fix the url in Jenkins Configuration
  • Restart Jenkins using commands below

    brew services stop jenkins
    brew servics start jenkins
    

And that's it, you should be able to hit the site installed on the port 8080 if your firewall allows traffic on that port.

Afterwards, I recommend following these very detailed instructions by Jeffry van de Vuurst except for the build script. My modified version of the build script is available on my Github repo.I have updated it to work with the new folder structure Xamarin uses to put the .IPA files in and added a command to restore packages from sources other than the nuget.org feed.

Xamarin also provides documentation on setting up Jenkins. They recommend downloading the Jenkins app which uses the installer instead of Homebrew, so you may run into issues related to credentials.

There are two ways of triggering the builds Polling and Adding Git hooks. This post goes into the details of both. For simplicity, I use polling with Cron schedule of * * * * *.

Hockey App provides a way of pushing the builds on to the devices. It is fairly cheap and simple to setup. You can create multiple teams and push different builds on to their devices. In Jenkins world, "There is a plugin for that!" is very true. They of course have a plugin for the Hockey App. The setup is very straight forward and the details on setting it up can be found in another post by Jeffry.

At this point, the setup is pretty much all set. It works just fine if you have the provisioning profile downloaded on the build machines using Xcode. While setting all that up in the Apple Developer Portal, it is very important to remember to create the certificate on the build machine otherwise the build fails. It can't create an .IPA file because of the private key issues.

Whenever I ran into issues, I always went to the workspace folder of Jenkins, opened the solution in Xamarin Studio and built it. That revealed a lot of details on the problems that lead to a resolution.

In the previous post, we saw why Jenkins makes sense for Xamarin build, at least for now. If you have previously worked with continuous integration systems such as Team City, the steps in Jenkins will look familiar to you. The steps follow a logical flow. So, even if you're brand…

Read More

Continuous Integration For a Xamarin app, a Microsoft update

Recently, Microsoft ended up buying Xamarin. It was very much anticipated, it always felt more of a "when" than "if" and finally it happened. Microsoft made the Xamarin suites (most of it) available with the MSDN licenses. It removed a barrier for a lot of companies and independent developers. Now, if you're a .NET developer and want to build a cross platform application, you may not have to look beyond Xamarin.

In this series of mobile app development, we are going to first tackle the continuous integration.

In today's Enterprise world, the use of TFS is prevalent. It usually tends be an on-prem one. Thankfully, TFS allows us to create Git repositories. For now, it only supports HTTP. SSH is coming to TFS with Update 3.The timeline for features is here. I have also seen the on-prem TFS version is slightly behind the cloud one. The features mentioned here are not available in an on-prem version. There is some starter documentation by Xamarin but it may not be enough to see you though turbulence.

For the Xamarin apps, the Mac TFS build agent has gone through a lot of churn. It used to be VSO Agent.It is being deprecated in favor of the VSTS agent.The new agent didn't support on-prem TFS until version 2.101.0. I learned it the hard way. It is in a preview state as of June 20th, 2016. It lacks community support. If you hit a road block, you may have to dig into code yourself (yay, OSS!) or open up a ticket on GitHub and wait for the team's reply.

Based on the feature gaps between visual studio online and TFS on-prem, lack of community support, confusing MSDN articles and issues with the preview version of Mac Build Agent, I'd recommend not to use TFS for the continuous integration purposes, at least for now. They are moving in the right direction but not fully there yet.

Instead, the better option is Jenkins. It is free. It has a great community behind it. It has rich plugin ecosystem. It has a nice upgrade and downgrade functionality. If for some reason, upgrading a plugin or Jenkins itself is not working the way the previously installed version did, you can simply go back to that version without too much of a hassle. In other words, it just works!

The next post in the series is available at http://aradhye.com/continuous-integration-for-xamarin-app-with-jenkins-and-deployments-with-hockey-app/

Recently, Microsoft ended up buying Xamarin. It was very much anticipated, it always felt more of a "when" than "if" and finally it happened. Microsoft made the Xamarin suites (most of it) available with the MSDN licenses. It removed a barrier for a lot of companies and independent developers. Now,…

Read More