It turns out that I can get what I want by using artifact dependencies and "Build Finished" build triggers.
How to handle TeamCity dependencies for both artifacts and build triggering
-
01-06-2022 - |
Question
So I've got a couple of projects (A, B, C, D) where the dependencies look like this:
B
/ \
A D
\ /
C
That is, B and C depend on artifacts from A, and D depends on artifacts from both B and C.
I'd like to do a couple of things:
- Artifacts from previous successful builds are used in projects. For instance, when a build for project C is triggered, it uses project A's artifacts that have been previously verified to be good (aka tests pass).
- Triggered builds in project also trigger builds in project that depend on them. For instance, if a change is made in the B project, the B project is built and then the D project is built using artifacts from the just-built B project. A change in project A rebuilds everything in this order A, B and C (concurrent), then D.
I can achieve VCS triggered builds in the "Build Triggers" section.
I can achieve artifact dependencies in the "Dependencies" section by adding an artifact dependency from "Last successful build" and pulling over my artifacts.
I don't know how to achieve triggered builds in the correct order in the correct dependency chain. If I make project A a snapshot dependency of project B, when B needs to be built, it rebuilds A and then rebuilds B. Similarly, if a change happens in A, only A is rebuilt. I would like a change in A to cause a rebuild for all my projects.
Is this possible? I'm on TeamCity 7.1.3.
Solution 2
OTHER TIPS
You can also use a VCS trigger. Set B and C have A as a snapshot dependency, and D with a snapshot dependency on B and C. Then set on all 4 a VCS build trigger, making sure to check the option "Trigger on changes in snapshot dependencies".
This way -
Change in A: A is rebuilt, this then triggers a build of B and C. These builds then also trigger a build of D, all in correct order.
Change in B or C: If A is unchanged, they use the existing build, rebuild themselves, and trigger build of D:
Change in D: If A, B, and C are unchanged, it uses the existing builds and builds a new D.
I'm using this setup on version 7.1.2