Remote-pairing

Setting Continuous Integration on Visual Studio Online

Today I want to give you an overview how easily you can bring Continuous Integration to your project using Visual Studio Online service.

Intro

As you may remember from my last post I aimed to set up CI for my project. Firstly – using Travis but it turned out to be hosted on Linux servers, so from .NET family we have .NET Core there only. Later on with TeamCity, however, it appears to be standalone software installation and I was looking for more SaaS approach. And the solution was closer than I could have thought! This is visualstudioonline which gives you plenty of great features – and one of them is CI.

Assumptions

This post is shaped more like a tutorial, so please let me tell you what is my starting point = what are my assumptions.

  1. I have some code written.
    • It is not rocket science, just template WebApp from Visual Studio so far.
  2. The code has some unit tests.
    • Nothing special again, but tests are written in xUnit so I’ll know if NuGet packages are being resolved properly and if the build can fail when something goes wrong (one test intentionally fails).
  3. The code is pushed to GitHub.

Setting CI for the project

Chances are you already have Microsoft Account (live.com) which lets you register your Visual Studio or maybe you use outlook.com email… but – even if not, creating an account there is as straightforward as everywhere, so just create one if you don’t have it yet. Now go directly to visualstudioonline.com site and click ‘New team project‘ – which brings you to this modal:

Here you give the name for your coding space which becomes your URL address as well (as you can see I made a terrible typo there 🙁 ),  you can name your project – MyFirstProject is picked by default, and lastly – choose where the project should be hosted in. I recommend choosing the location which is the closest one to yours. USA is default option here so I changed it to West Europe.

On next screen you get the git repository for your project, however, I won’t use that one, because I want to integrate with existing Github repository that is already in use. Thus I’ll set the build from the external repository:
What interest me is new build definition for Visual Studio:

Remember to check Continuous Integration that we are aiming for in this post 🙂
Now it’s time to integrate GitHub repository, so get to the corresponding tab and click ‘Manage‘:
As far as you don’t have any services defined here yet, please add New Service Endpoint based on GitHub:

The adequate integration modal window is displayed where you can authorize your GitHub. Clicking ‘Authorize‘ should open a new window (ensure your browser doesn’t block it) where you can log in to your GitHub account.

When you’ll be successfully authorized, you should see such prompt:

Now let’s ensure everything is in place in the way it should – suitable repository and branch should be picked:

And save the build!

It looks like we’re all set up. Now it’s time to see it in action – just Queue new build

Build luckily… fails! This is what we were actually expecting – remember this intentional failing test? It was nicely caught by CI:

I have to fix the code now, push changes to the repository and wait for the automatically scheduled build… and it works!

Here you can see build history – the first build was created manually by myself – and following one – automatically by TFS!

And that’s really it! I hope it was an understandable set of steps to reproduce – this service is quite intuitive, so I bet you won’t have any problems with setting one for yourself. Thank you for today and hopefully see you in next post!

Bonus

I always liked building badges on other programmers GitHub projects sites which immediately gives an overview if project is stable at this point of time – just like this  😉

You can easily get such badge link on Visual Studio Online as well – just go to edit page of your build definition and find ‘General‘ tab to enable badge for this project. You’ll be provided with a special link which gives you a small image of your health outline.

If you want to put this into your Readme file, you can do it with your fingers and push the changes – or use a dedicated tool called prose.io and edit it in a more user-friendly way.

No matter what you prefer, you can end up with such proud project badge as I did 🙂

Cheers!

Somewhat experienced programmer who tries to find intrinsic meaning in each act he does. Increasingly builds his courage to let his life be driven by passion. Currently giving blogging a whirl.

3 thoughts on “Setting Continuous Integration on Visual Studio Online”

  1. Wishing you the best of luck for all your blogging efforts. This is my first opportunity to chat this website. I found some interesting things and I will apply to the development of my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *