Setting up continuous integration from GitHub to NuGet using MyGet

It's been a while since my last blog post so I decided to dust of my good ol' Blogger account and get to it. I recently relocated from sunny South Africa to begin my brand new career in the beautiful Netherlands and I must say that I'm absolutely loving it!

My first task was to implement continuous integration on one of the (soon to be) open source projects to deliver packages on NuGet. After finding plenty of resources on the web about TeamCity, AppHarbour and Octopus Deploy, I finally decided on using MyGet which delivers a NuGet-as-a-Service experience.

The main goal is to have a build server up in the sky (MyGet) that builds the latest stable branch of my solution on every commit (from GitHub) and runs the automated unit tests. If all the unit tests pass, it needs to increment the version number, create a NuGet package and deploy it to my (private) MyGet repository for UAT. After approval, the package owner will hit the magic button to push the package to a public package repository like NuGet.

Creating the MyGet package feed

The first thing we need to do is create a MyGet package feed. Head over to MyGet.org, log in and click the big ‘New Feed’ button.

image

Next, we need to add a new build source from GitHub by going to the Build Services section of the feed properties, where we click ‘Add build services…’ and by choosing ‘from GitHub’

image

This will prompt you to link your GitHub account with MyGet and after authorisation, we need to select the repository we want to link. In my case, it is ‘NugetCI’ and click ‘Add’.

image

Once it has been added, we can change additional properties like what branch we want to pull, versioning semantics etc., by clicking ‘Edit’.

To keep things simple, we will assume the defaults.

Build baby, build!

Now all that is left to do is to make some changes and commit it to my repo on GitHub. Once it has synced, it queues up a new build after a short while.

image

This will attempt to build the project as well as look for any unit tests to run. If everything was successful, we will be presented with a green success icon.

We can see our brand new deployed NuGet package from the Packages section and download it from the feed https://www.myget.org/F/fanies-feed/

Get it to NuGet

Lastly, we need to push it to NuGet. To do this, we need to get our API Key from NuGet, which we will find under the ‘My NuGet.org Account’ page in NuGet.

image

After heading back to MyGet, we edit the default ‘NuGet.org’ package source from the Package Sources section and add the API key from NuGet under Authentication:

image
image

Now we can push packages to NuGet. We do this by going to the Packages section and clicking the tiny push icon

image

MyGet will proceed to invoke NuGet’s API pushing our package to the applicable NuGet feed. One can also enable mirroring to automatically push packages periodically to NuGet.

That’s all folks

We’ve barely scratched the surface of MyGet’s features but I was so excited to share my find on this and I was quite impressed by all the nifty things you can do. Everything is simply clean and to the point, it even picks up your .nuspec files within each project for building more advanced NuGet packages. I hope to write more on this subject in the future.

Till next time!