Last updated

TeamCity from JetBrains is a popular continuous integration server that supports a variety of different version control systems and build runners. Octopus Deploy and TeamCity can work together to make automated, continuous delivery easy.

When using Octopus Deploy with TeamCity, TeamCity will usually be responsible for:

  • Checking for changes in source control.
  • Compiling the code.
  • Running unit tests.
  • Creating NuGet packages for deployment.

While Octopus Deploy will be used to take those NuGet packages and to push them to development, test and production environments.

Integration with TeamCity involves two major parts:

  1. Creating the NuGet packages from your applications.
  2. Optionally, when a build completes, having TeamCity make requests to your Octopus Server to:
    • Create releases
    • Trigger deployments and/or
    • Promote releases when a build completes

Installing the Plugin

To make integrating with TeamCity easy, you can use the Octopus Deploy plugin for TeamCity that's available in the Jetbrains Plugin Repository. You can install this directly in TeamCity in the Administration ➜ Plugins List or manually. The TeamCity documentation has further instructions and options for installing plugins.

Creating Octopus-compatible NuGet Packages Using TeamCity

Octopus requires that you package your applications into NuGet packages, whether or not you are using TeamCity. There are many ways to create Octopus-compatible NuGet packages, but the easiest way is with OctoPack.

Using OctoPack
For more information on using OctoPack to create NuGet packages, see using OctoPack.

When you set up your build configuration in TeamCity, use either the MSBuild runner or the Visual Studio build runner. At the bottom of the runner settings, you'll see some options to run OctoPack during the build:

The OctoPack package version setting should evaluate to a version number with multiple parts (e.g., 1.3.7). It cannot be a single number. You may want to edit the General Settings for your project to ensure that the TeamCity build number uses multiple parts:

With these options selected, NuGet packages will automatically be created using the version number of the current build. OctoPack will ensure that these packages appear in the artifacts tab of TeamCity:

Can't use OctoPack?
Don't worry, TeamCity comes with a built-in NuGet Pack build step that you can use to package up Octopus-compatible NuGet packages. Just point it to your .csproj file, or a .nuspec file and TeamCity will package up your project for you. Just be aware that OctoPack has extra features (like adding website content files by convention) but at the end of the day it's just producing a NuGet package.

Using Octopus as a Package Repository

Octopus can be used as a NuGet package package, or can be configured to use an external feed (such as retrieving them from TeamCity).

To push packages to Octopus during the OctoPack phase, enter the NuGet endpoint url into the Publish packages to http field, and an API key in the Publish API Key field. OctoPack will then push the packages when the solution is built. You'll find the URL to your repository on the Library ➜ Packages tab in Octopus. Simply click the Show examples link to see options to upload packages including the repository URL.

Consuming the TeamCity NuGet feed in Octopus

Octopus 3.4+ requires TeamCity 9.0+ due to compatibility problems with the older NuGet v1 feed implemented by earlier versions of TeamCity. Refer to this thread and this GitHub Issue for more details.

TeamCity 7 and up can act as a NuGet repository. You can enable this by navigating to Administration ➜ Nuget Settings and enabling the inbuilt NuGet server. Any build artifacts ending with .nupkg will automatically be served as NuGet packages, which Octopus can consume.

Connect Octopus to Your TeamCity server

  1. In the Octopus Web Portal navigate to Library ➜ External Feeds.
  2. Click ADD FEED.
  3. Leave the feed type as NuGet Feed.
  4. Enter a name for the feed.
  5. Enter the authenticated feed URL.
  6. Click SAVE.

Once added, the TeamCity feed will appear in the NuGet feed list.

You can use the Test link to make sure that the NuGet package is available, before creating your Octopus project:

Tip: delayed package publishing
NuGet packages created from your build won't appear in the TeamCity NuGet feed until after the build fully completes. If you plan to trigger a deployment during a build, this creates a problem: the package won't be in the feed until the build is published, so you won't be able to deploy it.

The solution is to configure a secondary build configuration, and use a snapshot dependency and build trigger in TeamCity to run the deployment build configuration after the first build configuration completes. The video below demonstrates how to do this.

Creating and Pushing Packages From TeamCity to Octopus

In version 4.38.0 of the TeamCity Plugin we have added a new build runner that can be used to package your applications as either a NuGet or Zip formatted package.

Octopus Pack

In version 3.3.1 of the TeamCity Plugin we have added a new build runner that can be used to package and push your applications from TeamCity to Octopus.

Octopus Push

Triggering Deployments From TeamCity

The Octopus TeamCity plugin comes with these custom build runners:

  1. Octopus Deploy: Pack (TeamCity plugin 4.38.0 or newer) Create a NuGet or Zip formatted package.
  2. Octopus Deploy: Push Packages (Octopus 3.3 and TeamCity plugin 3.3.1 or newer) Push packages to the Octopus Deploy built-in repository, optionally using the TeamCity zip feature to create packages on-the-fly.
  3. Octopus Deploy: Create Release Creates a new release in Octopus Deploy, and optionally deploys it to an environment.
  4. Octopus Deploy: Deploy Release Deploys an existing release to a new environment.
  5. Octopus Deploy: Promote Release Promotes an existing release from one environment to another.

The plugin is simply a wrapper for Octo.exe, the Octopus command line tool for creating and deploying releases.

Using the Plugin With Linux Build Agents

Traditionally the Octopus TeamCity plugin required a Windows build agent to work. As of version 4.2.1 will run on Linux build agents if they meet either one of the following requirements:

  1. Have .NET Core installed on the build agent and in the PATH such that the dotnet command runs successfully. To install, follow the linked guide to install the .NET Core SDK for your distribution. Ensure that the dotnet command runs successfully. From version 4.15.10 of the plugin .NET Core v2 is required.
  2. Have the Octo command line tool installed and in the PATH such that the Octo command runs successfully. To install, download the .tar.gz for you system from the Octopus download page, extract somewhere appropriate and symlink Octo into your PATH. Again, ensure that Octo runs successfully. On Ubuntu you may need to install libunwind8 using your package manager.