A few weeks back, BitBucket launched a new version of their API and web hooks. It comes with a number of changes, but one change we like very much is support for OAuth tokens for pretty much anything, including cloning repositories.

MyGet has had support for building and packaging code from BitBucket for a long time. However up until now we had to ask for credentials in order to be able to clone and build a repository. With the changes introduced in this new API, this is no longer needed! Let's see how we can build a NuGet or npm package from BitBucket without handing our credentials to MyGet.

From an existing (or new) MyGet feed, navigate to Build Services and add a new build source. MyGet supports various sources that provide Git, Mercurial and Subversion repositories. Let's add one from BitBucket.

Before we can see our repositories, we'll have to tell BitBucket that MyGet can access our profile information and a few other things.

Once we have done that, we can pick the repository we want to clone and build. Note that by default MyGet registers a webhook with BitBucket, so that whenever we make a code change and push it to BitBucket, a build is triggered on MyGet. Automatically.

Whether your repository contains a C#, VB.NET or an npm project doesn't matter. The standard conventions will produce a build for many project types. If customization is needed or to have full control over your build, add a build script to do so.

Once a build finishes, we can see the packages it produced. We can test our NuGet, npm or VSIX packages from our MyGet feed. And once we are happy with them we can push them through to NuGet.org or Npmjs.org.

Happy packaging!