Many teams are working with Visual Studio Online (VSO), a hosted Team Foundation Server that provides source control and issue tracking as a cloud service. While VSO comes with a build server as well, lots of developers prefer to use TeamCity for their continuous integration story because of its advanced features to automatically run builds for feature branches, automatic merge and many others.
TeamCity supports building projects that are hosted on Visual Studio Online, the only thing we have to do is add a VCS root to our build configurations. Depending on the version control system used for the project (Git or Team Foundation Version Control – TFVC), this will be slightly different. Let’s have a look at our options.
Enabling alternate credentials
Independent from the version control system used, we will have to enable alternate credentials support on our Visual Studio Online account. Applications that work outside the browser, such as the git client or the command-line TFS client, require basic authentication credentials to work. By editing our VSO profile, we can set a secondary username that can be used for these scenarios.
After navigating to our VSO account portal, we can use the menu at the top-right to edit our profile. The Credentials tab lets us enable alternate credentials. After clicking Enable alternate credentials, we can set a secondary username and password we can use later on.
After saving our changes here, we can proceed with connecting TeamCity to Visual Studio Online version control.
Connecting to Visual Studio Online Git
For teams embracing Git source control with Visual Studio Online, TeamCity setup is really easy. From the Administration section, we can create a new project from URL. Next, we can enter the URL to our VSO Git repository and provide the alternate credentials we’ve just set up. TeamCity will auto-detect we’re using a Git repository.
Connecting to Visual Studio Online TFVC
Projects that are using Team Foundation Version Control (TFVC) can leverage TeamCity in their projects, too. The workflow to get started with a new project is the same: from the Administration section we can create a new project from URL, entering the URL to our Visual Studio Online project’s TFS path. This typically looks like https://accountname.visualstudio.com/DefaultCollection/$/ProjectName. For credentials, we can enter our Microsoft Account credentials, or use the alternate credentials created earlier.
Note that for TeamCity versions < 8.1.5 and older versions of Team Explorer, the Microsoft Account name has to be prefixed with ##LIVE##\.
Creating the Build Configuration
Once we have connected to Visual Studio Online, TeamCity will try to identify potential build steps we can use. It will browse our repository and look for Visual Studio solution files, projects, batch files, NuGet packages that have to be restored and so on. We can use these automatic steps, or add our own to fine-tune our build process.
When at least one build step is configured, we can start our build. It is possible to fine-tune our version control integration from the build configuration’s Version Control Settings. In here, we can configure what our branch structure looks like so that TeamCity automatically runs the build configuration for any feature branch we have. We can also modify the VCS Changes Checking interval and change when to check VSO for changes.
Using a Trigger, a build can automatically be started when chenges are checked in to VSO. The VCS Trigger must be added to the build configuration to do this. Optionally, we can build for every single change, accumulate check-ins and so on.
Many other triggers are available, such as the Schedule Trigger which starts a build at a given time. The Finish Build Trigger can start a build once another build has been finished. We can also monitor NuGet feeds and trigger a build when a given dependency changes.
TeamCity is a great companion to Visual Studio Online for many scenarios. Happy building!