CI With VSTS And Bitbucket
How to make Continuous Integration with Bitbucket and VSTS, when Bitbucket is not a default service inside VSTS.
In the previous blog post I described how to make a basic CI setup with VSTS using a repository hosted in VSTS. Bitbucket is a very popular source code repository, unfortunately not a default choice in VSTS, like GitHub etc. In this post I’ll show the steps required to make Bitbucket work as repository. This post will use some of the concepts described in my previous blog post. The build will also run on a local build agent, VSO agent.
Making a repository
The first step is to make a repository at Bitbucket and make an initial commit. When the commit is made, copy the https url of the repository.
VSTS Bitbucket Service endpoint
Because there is no default hook in VSTS to support Bitbucket, we need to create it as external git. Navigate to the collection settings for your project, by selecting the ‘gears’ icon in the upper right corner of your project. Select the Services tab and click the New Service Endpoint. From the menu select External Git. A dialog is displayed. Add a Connection name, this is just your identification of the service endpoint. The Server Url is the fully qualified url we copied from the Bitbucket homepage. As we used https username and password is the ones you use for regular https usage of the repository.
VSTS build needs some permissions to use this external git, during a build process. Navigate to the Default collection a level above your corrent project and select the Security tab. Locate Project Collection Build Administrators and ensure Edit Collection-level information is set to Allow. If not you’ll get an error during the build process.
Adding a build definition
Navigate to your VSTS project again and select the Build tab. Click the + to create a new build definition. I’m using the Xamarin.iOS. From the template select Remote git repository (note the name difference :)). Once created, you can now edit the details.
From the Build menu item of the build definition, add the relative path to the solution, sln file. (hint: If you get this one wrong, you can use the build console output, to see the fully qualified path, and easy correct it afterwards). Next you need to select the Repository menu item. The Repository type should already be set to external git (not remote :)). Refresh the Connection and select the Bitbucket service endpoint we created earlier, leave the Repository name blank. The service endpoint is already fully qualified. Save the build definition.
Ensure to update your VSO build agent. I used a previous version and had issues with username and password for the external git, not being passed along to the build agent, causing the build to fail (see this issue). Updating an existing agent is the same as installing a new one. Navigate to the agents directory where the package.json is located and execute the following command.
When all steps are completed, ensure the VSO agent is running and queue a new build. (Note, if you are build a Xamarin project, you need a business license.) When the build starts, a console is displayed inside the browser where you can follow all steps along the build process. If the sln path is incorrect, this is also where you can see the current resolved path.
After a couple of permission errors as described above and incorrect sln path, the result should be this, a green build
comments powered by Disqus