Race condition Creating Nupkg, uploading to Artifactory and then Creating Release with TeamCity Plugin

It seems that TeamCity does not wait for artifacts to be completely uploaded before executing the next build step.
Has anyone written a TeamCity build script that uploads an Artifact to an external repository (Artifactory or Nexus) and then immediately execute another build step that downloads that Artifact from the repository?
This being more of a TeamCity question, perhaps I should post to their support forum.

I am using TeamCity to create three Nuget packages using MSBuild and *.nuspec files. The TeamCity step automatically uploads the nupkg files to Artifactory via the TeamCity Artifactory plugin.
The next three TeamCity build steps use the Octopus Deploy plugin to create a release for each of these nupkg files.
The problem is the first one.
The first Octopus Deploy create release build step does not see the recently-created nupkg file and instead grabs the previous version.
The second and third work fine.
It appears to be some sort of race condition.
To illustrate, here is what is happening.

  1. TeamCity Step 1
  • Create V.60 server nupkg
  • Create V.60 Client nupkg
  • Create V.60 Standalone nupkg
  • Upload all 3 nupkg files to Artifactory
  1. TeamCity Step 2
  • Create Octopus Release V.60 for Server, grabbing the most recent version of the Server nupkg file from the repo
  1. TeamCity Step 3
  • Create Octopus Release V.60 for Client, grabbing the most recent version of the Server nupkg file from the repo
  1. TeamCity Step 4
  • Create Octopus Release V.60 for Standalone, grabbing the most recent version of the Server nupkg file from the repo

We end up with

  • Octopus Release V.60 Server contains V.59 Server nupkg file
  • Octopus Release V.60 Client contains V.60 Client nupkg file
  • Octopus Release V.60 Standalone contains V.60 Standalone nupkg file

I am struggling with how to debug this race condition.
Perhaps the TeamCity artifactory plugin does not actually wait for artifacts to complete their upload before starting the next build step.
I will try to insert a PowerShell script to sleep for 10 seconds in between and see if that solves the issue.
Any and all advice is appreciated.

Hi,

Thanks for reaching out. This is in fact a TeamCity question, but its absolutely fine to ask it here :). What you could do is instead of having the “Create Release” steps on the same build configuration, setup a separate configuration for these that is only triggered after the first build configuration finished successfully. Something like this:

  1. Build Configuration 1 - Compile your code and push packages to Artifactory.

  2. Build Configuration 2 - Create all the Octopus Releases. This build config should only be executed if the build config 1 was successful.

I’m 90% sure that TeamCity won’t finish the build from Build Configuration 1 until it pushes all the packages. If that doesn’t happen, you can always add a step at the beggining of Build Configuration 2 that does either of the following:

  1. [Recomended] Add a script step that consults the Artifactory repo to see if the Packages with version X are there. If they are, create the Octopus Releases. If they are not, fail the build.

  2. Add script with a sleep timer to give TeamCity some time to finish pushing the package. In Powershell It’ll be Start-sleep -seconds 60.

Hope that helps!
Dalmiro