In my previous post I showed how to integrate BitBucket with VSTS. This is based on a customer scenario. You can find the details in the previous post. The picture below shows the full end-to-end Story.
In this blogpost I will focus on the build process.
Here are the requirements of our customer:
- Build on check-in (CI) – I already covered this in my last post.
- Build online
- Build based on a Cake build script
- Run SonarQube analysis during build
- Send notifications to HipChat which is the IM chosen by the team
To be able to cover all of this I had to do some pre-work
1. Create a HipChat account
2. Set up a SonarQube server. I got my SonarQube server running on a virtual machine running on Azure pretty fast following this tutorial. I really just wanted to make sure communication works so I didn’t do anything special and just used the testserver which isn’t meant to be used in production.
- Download Java
- Follow the SonarQube guidance here for installation of SonarQube.
- Start the server (e.g. with StartSonar.bat) . In my case it was running on an Azure virtual machine running Windows 10.
Per default it’s listening on port 9000. You have to make this port available in public. You can do this in the Azure portal (see image below).
Make sure you can access port 9000 of your VM from outside before you continue. Otherwise your SonarQube integration won’t work. It should look something like this, however if you didn’t use SQ before without a project.
3. Get a demo application.
Of course I could have taken any random hello-world demo application for Xamarin. To have something more real-world like I chose this one: https://github.com/jamesmontemagno/Hanselman.Forms
Running a Cake Build Script in VSTS
Ok this is really the easy part. My customer had a full Cake build script available already. Just add a new build step in the Build definition of VSTS. This will open up a number of predefined build steps. If you don’t see Cake here you haven’t installed it yet. Just click “Check out our Marketplace”. Yes! There is a marketplace for buildsteps. A kind of app store for VSTS extensibility. Pretty cool.
This will take you to https://marketplace.visualstudio.com . Search for Cake there, click the result you see.
On the upcoming page click Install. This will install this extension directly into your VSTS account.
Now if you navigate back you’ll find a new build task.
Click “Add” to add a build step based on Cake.
All that’s left to do is to provide the name of your Cake script in the properties on the right. You can specify more parameters, however in our case this was sufficient. The Cake script had to be added to SourceControl before to make it available to the build.
Unfortunately I can’t share the Cake script with you. For the upcoming steps I will skip the Cake aspect as we now know that it is working. Instead I will do a “regular” build without cake so that you can follow the tutorial.
Building for Android with VSTS without Cake
As I said my demo application was https://github.com/jamesmontemagno/Hanselman.Forms . To build this application I needed either a Cake script which covers everything. Or I can just trigger a regular build. Here’s how I do a regular build. First I run .NuGet restore to make sure all required packages will be available. This can be done by adding a new build step “NuGet Installer”
Afterwards I specify the path to the solution.
After having restored I just need to really build the project. In VSTS we have a predefined Build Task for Xamarin Android builds.
Having added this step I specify which project to build. In my case I just want to build for Android. There are ways to integrate an iOS Buildsystem outside of VSTS however this is currently not covered in this scenario. I also specified the out directory to make sure that I know exactly where my results can be found.
To be able to use the results of the build later during deployment we have to publish the results in an artifacts folder. To do this I add another build step.
In my case I configure it to take the Android package (.apk) and create an artifact “droidartifacts”. I could put them on a share however I decide to just keep them on the server because I want to publish them to Hockeyapp using VSTS later.
We are basically done with the “pure” building of the application. It should already work, however we have additional tasks open. I will address those in the next posts.