A little while back I read about TeamCity Dependencies and thought it was a nifty idea but when I started using the feature I realized how powerful they are. Here, I try to explain the differences between Snapshot and Artifact dependencies in TeamCity, how to add them to your build configuration, and how I have used them and hopefully you will feel comfortable enough to use them too.
Snapshot Dependencies are a way to chain projects together by ensuring a project is run and finished before the depending project can start. With this feature, a build process made up of several build steps could be broken into independent projects while still maintaining the build order. Even further, depending on how you set up your dependency options, you could run two or more build concurrently.
To add a snapshot dependency, go to the Dependencies page within the project settings and click Add a new snapshot dependency. In the dialogue, select the build configuration you want the current configuration to depend. You can also select; do not run build if there is a suitable one, only use successful builds, run this build if dependency has failed, and run on the same agent. I typically select the first two options (do not run if there is a suitable one and only use successful builds) because I want to chain build projects together based on a revision in my VCS.
Personally, I feel the value of snapshot dependencies dramatically increases when paired with artifact dependencies.
TeamCity Artifacts are outputs from a build configuration. Artifact dependencies are used when you want a build to depend on the output, or part of the output, of a build.
To configure artifacts go to the General Settings page and enter artifact paths in the Save as Artifacts section. You have the flexibility to create one or many artifacts and each artifact is made up of one or more files. You can also make your artifacts a compressed (i.e zip) file.
To add an artifact dependency, go to the Dependencies page and click Add a new artifact dependency. In the dialogue, select the build configuration you want the current configuration to depend, then select where you want to get the artifacts. You can choose from Last successful build, Last pinned build, Last finished build, Build from the same chain, or Build with a specific build number or last finished build with a specific tag. Lastly, specify which artifacts you want to go where in the Artifact Rules section and whether you want to clean the destination paths before downloading artifacts.
As I mentioned earlier, I chain together build projects with snapshot dependencies based on the VCS root I’ve configured in TeamCity. I add artifact dependencies so I can build my source code once and reuse the built libraries in my unit and integration test projects and build a deployment package. I also use an artifact dependency to deploy the package to my development environment.
Have you used TeamCity Dependencies and how did you use them? I’m curious to hear about your experiences.