Configuring NuGet publish on TeamCity

In this post I'll describe the solution I used to publish/promote builds of 3 version of TeamCity.ServiceMessages library to via TeamCity.

Package Build Setup

I moved TeamCity.ServiceMessages builds to There are 3 active versions of the library. It was necessary to re-use build setup in TeamCity. So I used build configuration template for it. The template contains steps to fetch NuGet dependencies, to patch assemblies version, to build Visual Studio solution, to run NUnit tests under dotCover code coverage, and to package the library as NuGet package. The template is parametrized by library version and Git branch name.

I decided to avoid publishing from the template. It's not necessary to publish packages from all builds. I suppose, it's normal to have some test builds prior to releasing them. So the goal is to create a specific build(s) to implement publishing of selected package only

Package Publish Setup

The easiest way to implement publishing is to create a build configuration for each of package versions. This would make me to copy 3 same configurations.

There is another approach with help of Typed Parameters.

I created one build configuration with TeamCity reference instead of packages to publish in NuGet Publish runner:

Here I use the following *%serviceMessages.packagesToPublish%*.nupkg. I can specify wildcard as TeamCity Property in Build Parameters section of build configuration settings.

Next I specify %serviceMessages.packagesToPublish% property for the Build Parameters section of build configuration configuration:

Here I use Typed Parameter to implement drop-down. I also mark parameter as required in order to make TeamCity show custom run dialog for me on every run button click. This build is started only implicitly, so I have no build triggers.

I added an artifact dependency from all 3 of my build configurations. The values of %serviceMessages.packagesToPublish% are selected in the way to select only one of 3 NuGet packages.

Starting the Build

Now when I start the publish build I see the following dialog

I can select the the build configuration of the library with latest successful package I want to publish with NuGet. Thanks to Dependencies tab I can override the artifact if necessary.

Side Notes

Note, this trick will only work if you are able to write wildcards that matches only necessary packages that were downloaded from one build configuration. From the other hand, you may download packages from each configuration to different folders making wildcards even simpler

The project is available here

comments powered by Disqus