I have 2 build configurations in one project:
I want Deploy Code to run only if Build & Test Code built successfully, so I set up a snapshot dependency.
Does a snapshot dependency mean that Deploy Code will check out the same SVN revision as Build & Test Code and then run the NAnt script against that checkout, which will not contain the compiler generated post-build files? Or, will a snapshot dependency on Build & Test Code from Deploy Code mean that the NAnt will run against the post-build, working directory files of Build & Test Code on the build agent?
UPDATE:
It seems if I put a snapshot dependency on Build & Test Code for Deploy Code and I have a build of the latest revision for Build & Test Code, my NAnt script will deploy the post-build files for that build of Build & Test Code.
I would still like to confirm that I understand the concept, as I don't really understand the Team City documentation. I think I should probably make sure Deploy Code runs on the same build agent as Build & Test Code, otherwise I might run into a case where Deploy Code checks out the SVN revision and then just deploys the pre-build code files. Is this correct?
My confusion is mainly because it seems you have to have a VCS setup for Deploy Code. Is that because it needs it to compare revision numbers to the snapshot dependency?
By setting a snapshot dependency of a build (for example, build B) on another build's (build A) sources, you can ensure that build B will start only after build A is run and finished. We call build A a dependency build, whereas build B is a dependent build.
In Maven, a SNAPSHOT version is a version of the project/dependency that has not been released. This is indicated by suffixing SNAPSHOT to the version number. Here's an example: <version>1.0-SNAPSHOT</version> Copy.
From the Snapshot Dependency section of the Dependent Builds doco page:
A snapshot dependency from build configuration A to build configuration B enforces that each build of A has a "suitable" build of B so that both builds use the same sources snapshot (used sources revisions correspond to the same moment).
So the idea of a snapshot dependency is that you can run a build against exactly the same codebase as another build which has successfully run against it.
If you want the "deploy code" build to run only after "build and test code" has successfully run, create a snapshot dependency in the second build and make sure it's set to "Only use successful builds from the suitable ones".
Keep in mind that this has nothing to do with artefacts; the second build will simply pull the same codebase and recompile it all over again. If you want to deploy the artefacts created from the first build, then you want to be looking at artefact dependencies instead. This is just what Paul has written about in his answer and is the correct approach.
Regarding your update, it sounds like those post-build files are only available because they're still on the build agent after the first build. Try running the first build then "cleaning sources" on the agent and running the second build. You'll find the original compilation output is no longer there and it will fail. This is important because if you have multiple build agents or go some time between the two builds you simply can't rely on the output that isn't saved as artefacts still being there.
And yes, the TeamCity documentation is confusing :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With